#include <cstdio> #include <utility> #include <algorithm> using namespace std; const int NMAX = 5 * 100 * 1000 + 7; int n; pair<int, int> xsys[NMAX]; int main() { int result = 0; int r, w, t; (void)! scanf("%d", &n); for (int i = 0; i < n; i++) { (void)! scanf("%d %d %d", &r, &w, &t); if (r == 1) { xsys[i] = pair(w - t, 1); } else if (r == 2) { xsys[i] = pair(w - t, 2); } } /* for (int i = 0; i < n; i++) printf("xsys[%d] = (%d; %d) \n", i, xsys[i].first, xsys[i].second); */ sort(xsys, xsys + n); /* for (int i = 0; i < n; i++) printf("xsys[%d] = (%d; %d) \n", i, xsys[i].first, xsys[i].second); */ for (int i = 0; i < n; i++) { int n_elem[3] = {0, 0, 0}; for(; xsys[i].first == xsys[i + 1].first && i < n; i++) { n_elem[xsys[i].second]++; } n_elem[xsys[i].second]++; // printf("result: %d n_elem[1] = %d n_elem[2] = %d\n", result, n_elem[1], n_elem[2]); result += min(n_elem[1], n_elem[2]); } printf("%d\n", 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 42 43 44 45 46 47 48 49 50 51 52 53 | #include <cstdio> #include <utility> #include <algorithm> using namespace std; const int NMAX = 5 * 100 * 1000 + 7; int n; pair<int, int> xsys[NMAX]; int main() { int result = 0; int r, w, t; (void)! scanf("%d", &n); for (int i = 0; i < n; i++) { (void)! scanf("%d %d %d", &r, &w, &t); if (r == 1) { xsys[i] = pair(w - t, 1); } else if (r == 2) { xsys[i] = pair(w - t, 2); } } /* for (int i = 0; i < n; i++) printf("xsys[%d] = (%d; %d) \n", i, xsys[i].first, xsys[i].second); */ sort(xsys, xsys + n); /* for (int i = 0; i < n; i++) printf("xsys[%d] = (%d; %d) \n", i, xsys[i].first, xsys[i].second); */ for (int i = 0; i < n; i++) { int n_elem[3] = {0, 0, 0}; for(; xsys[i].first == xsys[i + 1].first && i < n; i++) { n_elem[xsys[i].second]++; } n_elem[xsys[i].second]++; // printf("result: %d n_elem[1] = %d n_elem[2] = %d\n", result, n_elem[1], n_elem[2]); result += min(n_elem[1], n_elem[2]); } printf("%d\n", result); return 0; } |