#include <algorithm> #include <cstdio> const int BASE = 1111111; const int CLEN = BASE*2; using namespace std; int r[504030]; int w[504030]; int t[504030]; int c[2][CLEN]; int main(int argc, char** argv) { int n; scanf("%d",&n); for(int i=0;i<n;i++) { scanf("%d%d%d", &(r[i]), &(w[i]), &(t[i])); } for(int i=0;i<n;i++) { c[r[i]-1][BASE+t[i]-w[i]]++; } int res = 0; for(int i=0;i<CLEN;i++) { res += min(c[0][i], c[1][i]); } printf("%d\n", res); 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 | #include <algorithm> #include <cstdio> const int BASE = 1111111; const int CLEN = BASE*2; using namespace std; int r[504030]; int w[504030]; int t[504030]; int c[2][CLEN]; int main(int argc, char** argv) { int n; scanf("%d",&n); for(int i=0;i<n;i++) { scanf("%d%d%d", &(r[i]), &(w[i]), &(t[i])); } for(int i=0;i<n;i++) { c[r[i]-1][BASE+t[i]-w[i]]++; } int res = 0; for(int i=0;i<CLEN;i++) { res += min(c[0][i], c[1][i]); } printf("%d\n", res); return 0; } |