#include <bits/stdc++.h>
#define nd second
#define st first
std::map<int, int> A, B;
int main() {
std::ios_base::sync_with_stdio(0); std::cin.tie(NULL);
int n;
std::cin >> n;
for (int i = 1; i <= n; i++) {
int k, w, t;
std::cin >> k >> w >> t;
if (k == 1)
A[w-t]++;
else
B[w-t]++;
}
int res = 0;
for (auto p: A) {
if (B.find(p.st) != B.end()) {
int x = (p.nd);
int y = B[p.st];
res += std::min(x, y);
}
}
std::cout << res << "\n";
}
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 | #include <bits/stdc++.h> #define nd second #define st first std::map<int, int> A, B; int main() { std::ios_base::sync_with_stdio(0); std::cin.tie(NULL); int n; std::cin >> n; for (int i = 1; i <= n; i++) { int k, w, t; std::cin >> k >> w >> t; if (k == 1) A[w-t]++; else B[w-t]++; } int res = 0; for (auto p: A) { if (B.find(p.st) != B.end()) { int x = (p.nd); int y = B[p.st]; res += std::min(x, y); } } std::cout << res << "\n"; } |
English