#include <iostream> using namespace std; const int maxSize = 1000007; int main() { ios_base::sync_with_stdio(0); int n, r, w, t; int ***deliveries; deliveries = new int**[maxSize]; for (int i = 0; i < maxSize; ++i) { deliveries[i] = new int*[2]; for (int j = 0; j < 2; ++j) { deliveries[i][j] = new int[2]; } } for (int i = 0; i < maxSize; ++i) { deliveries[i][0][0] = 0; deliveries[i][0][1] = 0; deliveries[i][1][0] = 0; deliveries[i][1][1] = 0; } cin >> n; for (int i = 0; i < n; ++i) { cin >> r; cin >> w; cin >> t; --r; w -= t; if (w < 0) { t = 0; w *= -1; } else { t = 1; } ++deliveries[w][t][r]; } int result = 0; for (int i = 0; i < maxSize; ++i) { result += min(deliveries[i][0][0], deliveries[i][0][1]); result += min(deliveries[i][1][0], deliveries[i][1][1]); } cout << result << endl; for (int i = 0; i < maxSize; ++i) { for (int j = 0; j < 2; ++j) { delete [] deliveries[i][j]; } delete [] deliveries[i]; } delete [] deliveries; 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 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | #include <iostream> using namespace std; const int maxSize = 1000007; int main() { ios_base::sync_with_stdio(0); int n, r, w, t; int ***deliveries; deliveries = new int**[maxSize]; for (int i = 0; i < maxSize; ++i) { deliveries[i] = new int*[2]; for (int j = 0; j < 2; ++j) { deliveries[i][j] = new int[2]; } } for (int i = 0; i < maxSize; ++i) { deliveries[i][0][0] = 0; deliveries[i][0][1] = 0; deliveries[i][1][0] = 0; deliveries[i][1][1] = 0; } cin >> n; for (int i = 0; i < n; ++i) { cin >> r; cin >> w; cin >> t; --r; w -= t; if (w < 0) { t = 0; w *= -1; } else { t = 1; } ++deliveries[w][t][r]; } int result = 0; for (int i = 0; i < maxSize; ++i) { result += min(deliveries[i][0][0], deliveries[i][0][1]); result += min(deliveries[i][1][0], deliveries[i][1][1]); } cout << result << endl; for (int i = 0; i < maxSize; ++i) { for (int j = 0; j < 2; ++j) { delete [] deliveries[i][j]; } delete [] deliveries[i]; } delete [] deliveries; return 0; } |