#include <iostream>
#include <vector>
#include <map>
typedef long long ll;
using namespace std;
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);
int n;
cin>>n;
vector<pair<ll,ll>>odBoku;
vector<pair<ll,ll>>odDolu;
int r,w,t;
for(int i=0;i<n;i++){
cin>>r>>w>>t;
if(r==1){
odBoku.push_back({w,t});
}else{
odDolu.push_back({w,t});
}
}
map<ll,pair<ll,ll>> hit;
for(auto el:odDolu){
hit[el.first-el.second].first++;
}
for(auto el:odBoku){
hit[el.first-el.second].second++;
}
int o=0;
for(auto el:hit){
o+=min(el.second.first,el.second.second);
}
cout<<o<<"\n";
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | #include <iostream> #include <vector> #include <map> typedef long long ll; using namespace std; int main(){ ios_base::sync_with_stdio(0);cin.tie(0); int n; cin>>n; vector<pair<ll,ll>>odBoku; vector<pair<ll,ll>>odDolu; int r,w,t; for(int i=0;i<n;i++){ cin>>r>>w>>t; if(r==1){ odBoku.push_back({w,t}); }else{ odDolu.push_back({w,t}); } } map<ll,pair<ll,ll>> hit; for(auto el:odDolu){ hit[el.first-el.second].first++; } for(auto el:odBoku){ hit[el.first-el.second].second++; } int o=0; for(auto el:hit){ o+=min(el.second.first,el.second.second); } cout<<o<<"\n"; } |
English