#include<bits/stdc++.h> #define f first #define s second using namespace std; const int N = ((int)(1e6))+50; int n; int cnt1[2*N],cnt2[2*N]; long long wynik; int main(){ ios_base::sync_with_stdio( 0 ); cin.tie( 0 ); cout.tie( 0 ); cin>>n; int r,w,t; for (int i = 0; i < n; i++){ cin>>r>>w>>t; int value = (w - t)+N; if(r == 1){ cnt1[value]++; } else { cnt2[value]++; } } for (int i = 0; i < 2*N; i++){ if((cnt1[i] > 0) && (cnt1[i] > 0)){ wynik += min(cnt1[i], cnt2[i]); } } cout<<wynik; 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 30 31 32 | #include<bits/stdc++.h> #define f first #define s second using namespace std; const int N = ((int)(1e6))+50; int n; int cnt1[2*N],cnt2[2*N]; long long wynik; int main(){ ios_base::sync_with_stdio( 0 ); cin.tie( 0 ); cout.tie( 0 ); cin>>n; int r,w,t; for (int i = 0; i < n; i++){ cin>>r>>w>>t; int value = (w - t)+N; if(r == 1){ cnt1[value]++; } else { cnt2[value]++; } } for (int i = 0; i < 2*N; i++){ if((cnt1[i] > 0) && (cnt1[i] > 0)){ wynik += min(cnt1[i], cnt2[i]); } } cout<<wynik; return 0; } |