#include<bits/stdc++.h>
using namespace std;
int main(){
map<int,pair<int,int> > mapp;
int n;
cin >>n;
for(int i=0;i<n;i++){
int w,a,b;
cin >>w >>a >>b;
if(w==1){
mapp[a-b].first++;
}
else{
mapp[a-b].second++;
}
}
int ans=0;
for(auto pr : mapp){
ans+=min(pr.second.first,pr.second.second);
}
cout <<ans;
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | #include<bits/stdc++.h> using namespace std; int main(){ map<int,pair<int,int> > mapp; int n; cin >>n; for(int i=0;i<n;i++){ int w,a,b; cin >>w >>a >>b; if(w==1){ mapp[a-b].first++; } else{ mapp[a-b].second++; } } int ans=0; for(auto pr : mapp){ ans+=min(pr.second.first,pr.second.second); } cout <<ans; } |
English