#include <stdio.h> #include <stdlib.h> using namespace std; #define MAX_W 1000001 int main() { int n, r, w, t, idx, max1=0, max2=0, min1=MAX_W, min2=MAX_W; scanf("%d", &n); // int r1[2*MAX_W] = {0}; // int r2[2*MAX_W] = {0}; int *r1 = new int[2*MAX_W](); int *r2 = new int[2*MAX_W](); for(int i=0; i<n; i++) { scanf("%d %d %d", &r, &w, &t); idx = MAX_W + w-t; if(r == 1) { r1[idx]++; if(idx > max1) { max1 = idx; } if(idx < min1) { min1 = idx; } } else { r2[idx]++; if(idx > max2) { max2 = idx; } if(idx < min2) { min2 = idx; } } } int start = min1 < min2 ? min1 : min2; int stop = max1 > max2 ? max1 : max2; int res = 0; for(int i=start; i<=stop; i++) { res += r1[i] < r2[i] ? r1[i] : r2[i]; } printf("%d", res); delete [] r1; delete [] r2; 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 | #include <stdio.h> #include <stdlib.h> using namespace std; #define MAX_W 1000001 int main() { int n, r, w, t, idx, max1=0, max2=0, min1=MAX_W, min2=MAX_W; scanf("%d", &n); // int r1[2*MAX_W] = {0}; // int r2[2*MAX_W] = {0}; int *r1 = new int[2*MAX_W](); int *r2 = new int[2*MAX_W](); for(int i=0; i<n; i++) { scanf("%d %d %d", &r, &w, &t); idx = MAX_W + w-t; if(r == 1) { r1[idx]++; if(idx > max1) { max1 = idx; } if(idx < min1) { min1 = idx; } } else { r2[idx]++; if(idx > max2) { max2 = idx; } if(idx < min2) { min2 = idx; } } } int start = min1 < min2 ? min1 : min2; int stop = max1 > max2 ? max1 : max2; int res = 0; for(int i=start; i<=stop; i++) { res += r1[i] < r2[i] ? r1[i] : r2[i]; } printf("%d", res); delete [] r1; delete [] r2; return 0; } |