#include <cstdio>
#include <map>
using namespace std;
int N;
map<int, int> s[2];
int main() {
int r, w, t;
scanf("%d", &N);
for (int i = 0; i < N; ++i) {
scanf("%d %d %d", &r, &w, &t);
s[r - 1][w - t]++;
}
auto it1 = s[0].begin();
auto it2 = s[1].begin();
r = 0;
while (it1 != s[0].end() && it2 != s[1].end()) {
if (it1->first == it2->first) {
r += it1->second < it2->second ? it1->second : it2->second;
it1++;
it2++;
} else if (it1->first < it2->first) {
it1++;
} else {
it2++;
}
}
printf("%d\n", r);
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 33 34 35 36 | #include <cstdio> #include <map> using namespace std; int N; map<int, int> s[2]; int main() { int r, w, t; scanf("%d", &N); for (int i = 0; i < N; ++i) { scanf("%d %d %d", &r, &w, &t); s[r - 1][w - t]++; } auto it1 = s[0].begin(); auto it2 = s[1].begin(); r = 0; while (it1 != s[0].end() && it2 != s[1].end()) { if (it1->first == it2->first) { r += it1->second < it2->second ? it1->second : it2->second; it1++; it2++; } else if (it1->first < it2->first) { it1++; } else { it2++; } } printf("%d\n", r); return 0; } |
English