#include <iostream> #include <map> #ifdef HOME_ #define DEBUG(x) x #else #define DEBUG(x) #endif #define REP(x,n) for(int x=0;x<(n);++x) using namespace std; map<int, int> vert, horz; int n; int r,w,t; int main() { ios_base::sync_with_stdio(0); cin>>n; REP(x,n) { cin>>r>>w>>t; if (r==1) ++vert[t-w]; else ++horz[t-w]; } int wyn = 0; auto i1 = vert.begin(), i2 = horz.begin(); while (i1 != vert.end() && i2 != horz.end()) { if (i1->first < i2->first) ++i1; else if (i2->first < i1->first) ++i2; else { DEBUG( cerr << "kolizja na " << i1->first << "; " << i1->second << " vs " << i2->second << endl; ) wyn += min(i1->second, i2->second); ++i1; ++i2; } } cout << wyn; 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 | #include <iostream> #include <map> #ifdef HOME_ #define DEBUG(x) x #else #define DEBUG(x) #endif #define REP(x,n) for(int x=0;x<(n);++x) using namespace std; map<int, int> vert, horz; int n; int r,w,t; int main() { ios_base::sync_with_stdio(0); cin>>n; REP(x,n) { cin>>r>>w>>t; if (r==1) ++vert[t-w]; else ++horz[t-w]; } int wyn = 0; auto i1 = vert.begin(), i2 = horz.begin(); while (i1 != vert.end() && i2 != horz.end()) { if (i1->first < i2->first) ++i1; else if (i2->first < i1->first) ++i2; else { DEBUG( cerr << "kolizja na " << i1->first << "; " << i1->second << " vs " << i2->second << endl; ) wyn += min(i1->second, i2->second); ++i1; ++i2; } } cout << wyn; return 0; } |