#include <cstdio> #define MAX_N 500000 struct sam { long value; long r1; long r2; }; sam s[MAX_N] = {0}; int main() { bool found; int r; long n, w, t, u = 0, idx = 0, value; scanf("%ld", &n); for(long i = 0; i < n; i++) { scanf("%d%ld%ld", &r, &w, &t); value = w - t; found = false; for(long j = 0; j < idx; j++) { if(s[j].value == value) { if(r == 1) { s[j].r1++; } else { s[j].r2++; } found = true; } } if(!found) { s[idx].value = value; if(r == 1) { s[idx].r1 = 1; s[idx].r2 = 0; } else { s[idx].r1 = 0; s[idx].r2 = 1; } idx++; } } for(long i = 0; i < idx; i++) { if(s[i].r1 < s[i].r2) { u += s[i].r1; } else { u += s[i].r2; } } printf("%ld\n", u); 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 <cstdio> #define MAX_N 500000 struct sam { long value; long r1; long r2; }; sam s[MAX_N] = {0}; int main() { bool found; int r; long n, w, t, u = 0, idx = 0, value; scanf("%ld", &n); for(long i = 0; i < n; i++) { scanf("%d%ld%ld", &r, &w, &t); value = w - t; found = false; for(long j = 0; j < idx; j++) { if(s[j].value == value) { if(r == 1) { s[j].r1++; } else { s[j].r2++; } found = true; } } if(!found) { s[idx].value = value; if(r == 1) { s[idx].r1 = 1; s[idx].r2 = 0; } else { s[idx].r1 = 0; s[idx].r2 = 1; } idx++; } } for(long i = 0; i < idx; i++) { if(s[i].r1 < s[i].r2) { u += s[i].r1; } else { u += s[i].r2; } } printf("%ld\n", u); return 0; } |