#include <iostream>
#include <algorithm>
#include <set>
using namespace std;
const int OFFSET = 999999;
const int SIZE = 1999999;
const int TYPES = 2;
int main() {
ios::sync_with_stdio(false);
int n, r, w, t, x;
static int count[TYPES][SIZE] = {0};
int countR[TYPES] = {0};
set<pair<int, int> > supply[TYPES];
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> r >> w >> t;
x = w - t;
++count[r - 1][x + OFFSET];
++countR[r - 1];
supply[r - 1].insert(make_pair(w, t));
}
int result = 0;
for (int i = 0; i < SIZE; ++i) {
result += min(count[0][i], count[1][i]);
}
for (int i = 0; i < TYPES; ++i) {
result += (countR[i] - supply[i].size());
}
cout << result;
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 37 38 39 40 41 | #include <iostream> #include <algorithm> #include <set> using namespace std; const int OFFSET = 999999; const int SIZE = 1999999; const int TYPES = 2; int main() { ios::sync_with_stdio(false); int n, r, w, t, x; static int count[TYPES][SIZE] = {0}; int countR[TYPES] = {0}; set<pair<int, int> > supply[TYPES]; cin >> n; for (int i = 0; i < n; ++i) { cin >> r >> w >> t; x = w - t; ++count[r - 1][x + OFFSET]; ++countR[r - 1]; supply[r - 1].insert(make_pair(w, t)); } int result = 0; for (int i = 0; i < SIZE; ++i) { result += min(count[0][i], count[1][i]); } for (int i = 0; i < TYPES; ++i) { result += (countR[i] - supply[i].size()); } cout << result; return 0; } |
English