#include<bits/stdc++.h> using namespace std; const int MAX_W=1000000; const int ARR_SIZE = MAX_W*2; int tracks[2][ARR_SIZE] = {0}; int main(){ int n; cin >> n; int r, w, t; while(n--){ cin >> r >> w >> t; ++tracks[r-1][w-t-1+MAX_W]; } long long count = 0; for(int i=0; i<ARR_SIZE; i++){ count += min(tracks[0][i], tracks[1][i]); } cout << count; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | #include<bits/stdc++.h> using namespace std; const int MAX_W=1000000; const int ARR_SIZE = MAX_W*2; int tracks[2][ARR_SIZE] = {0}; int main(){ int n; cin >> n; int r, w, t; while(n--){ cin >> r >> w >> t; ++tracks[r-1][w-t-1+MAX_W]; } long long count = 0; for(int i=0; i<ARR_SIZE; i++){ count += min(tracks[0][i], tracks[1][i]); } cout << count; } |