#include<bits/stdc++.h> using namespace std; int n, r, w, t; int type1[2000002]; int type2[2000002]; int main() { cin >> n; for(int i = 0; i < n; i++) { cin >> r >> w >> t; w -= t; if(r==1) type1[w+1000000]++; else type2[w+1000000]++; } int result = 0; for(int i = 0; i <= 2000000; i++) { if(type1[i] > 0 && type2[i] > 0) result += (min(type1[i], type2[i])); } cout << result; 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> using namespace std; int n, r, w, t; int type1[2000002]; int type2[2000002]; int main() { cin >> n; for(int i = 0; i < n; i++) { cin >> r >> w >> t; w -= t; if(r==1) type1[w+1000000]++; else type2[w+1000000]++; } int result = 0; for(int i = 0; i <= 2000000; i++) { if(type1[i] > 0 && type2[i] > 0) result += (min(type1[i], type2[i])); } cout << result; return 0; } |