#include <bits/stdc++.h>
using namespace std;
const int N = 5e5+7;
const int BASE = 1e6;
const int P = 2e6+7;
int n, wyn;
int c[P][2];
int b[2], r;
vector<int> times;
int main() {
cin >> n;
int r, w, t;
for (int i = 0; i < n; i++) {
cin >> r >> w >> t;
c[w-t+BASE][r-1]++;
times.push_back(w-t+BASE);
b[r-1]++;
}
for (int j = 0; j < n; j++) {
int i = times[j];
if (c[i][0] && c[i][1]) {
wyn += min(c[i][0], c[i][1]);
c[i][0] = 0;
}
}
cout << wyn;
}
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; const int N = 5e5+7; const int BASE = 1e6; const int P = 2e6+7; int n, wyn; int c[P][2]; int b[2], r; vector<int> times; int main() { cin >> n; int r, w, t; for (int i = 0; i < n; i++) { cin >> r >> w >> t; c[w-t+BASE][r-1]++; times.push_back(w-t+BASE); b[r-1]++; } for (int j = 0; j < n; j++) { int i = times[j]; if (c[i][0] && c[i][1]) { wyn += min(c[i][0], c[i][1]); c[i][0] = 0; } } cout << wyn; } |
English