#include <bits/stdc++.h> #define st first #define nd second using namespace std; map<int, int> M1, M2; int main() { ios_base::sync_with_stdio(0); int n; cin>>n; for(int i=1; i<=n; ++i){ int type, w, time; cin>>type>>w>>time; if(type==1){ M1[w-time]++; } else{ M2[w-time]++; } } int ans=0; for(auto it=M1.begin(); it!=M1.end(); it++){ int w=it->st; ans+=min(M1[w], M2[w]); } cout<<ans; return 0; }
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 | #include <bits/stdc++.h> #define st first #define nd second using namespace std; map<int, int> M1, M2; int main() { ios_base::sync_with_stdio(0); int n; cin>>n; for(int i=1; i<=n; ++i){ int type, w, time; cin>>type>>w>>time; if(type==1){ M1[w-time]++; } else{ M2[w-time]++; } } int ans=0; for(auto it=M1.begin(); it!=M1.end(); it++){ int w=it->st; ans+=min(M1[w], M2[w]); } cout<<ans; return 0; } |