#include <ctime> #include <cassert> #include <iostream> #include <iomanip> #include <vector> #include <algorithm> #include <unordered_map> using namespace std; const int MAXN = 500000; #define FOR(i, n) for(int i = 0, __n = (n); i < __n; i++) int main() { ios_base::sync_with_stdio(0); int n; cin >> n; unordered_map<int,int> P[2]; FOR(i, n) { int r, w, t; cin >> r >> w >> t; P[r-1][t-w]++; } int total = 0; for (auto v : P[0]) { total += min(v.second, P[1][v.first]); } cout << total << endl; }
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 | #include <ctime> #include <cassert> #include <iostream> #include <iomanip> #include <vector> #include <algorithm> #include <unordered_map> using namespace std; const int MAXN = 500000; #define FOR(i, n) for(int i = 0, __n = (n); i < __n; i++) int main() { ios_base::sync_with_stdio(0); int n; cin >> n; unordered_map<int,int> P[2]; FOR(i, n) { int r, w, t; cin >> r >> w >> t; P[r-1][t-w]++; } int total = 0; for (auto v : P[0]) { total += min(v.second, P[1][v.first]); } cout << total << endl; } |