#include <bits/stdc++.h> using namespace std; multiset <int> A, B; set <int> C; int main() { ios_base::sync_with_stdio(false); int n; cin >> n; while(n--) { int r, w, t; cin >> r >> w >> t; if(r == 1) A.insert(w-t); else B.insert(w-t); } int x = 0; for(auto i : A) if(!C.count(i)) C.insert(i), x += min(A.count(i), B.count(i)); cout << x; return 0; }
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; multiset <int> A, B; set <int> C; int main() { ios_base::sync_with_stdio(false); int n; cin >> n; while(n--) { int r, w, t; cin >> r >> w >> t; if(r == 1) A.insert(w-t); else B.insert(w-t); } int x = 0; for(auto i : A) if(!C.count(i)) C.insert(i), x += min(A.count(i), B.count(i)); cout << x; return 0; } |