//Samochody Dostawcze #include <bits/stdc++.h> using namespace std; //--------------------------------------------// #define f first #define s second #define mp make_pair #define pb push_back #define all(x) x.begin(),x.end() #define iter(i, a, b) for(int (i)=(a);i<=(b);(i)++) #define iterl(i, a, b) for(int (i)=(a);i>=(b);(i)--) #define upgrade ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0) #define erase_dupl(x) sort(all(x));(x).resize(distance((x).begin(), unique(all(x)))) #define ll long long #define cll const ll #define cint const int #define pll pair<ll,ll> #define pil pair<int,ll> #define pli pair<ll,int> #define pii pair<int,int> //--------------------------------------------// unordered_map<int,int> WE; unordered_map<int,int> NS; vector<int> skrz; int sum; int main(){ upgrade; int ile; cin >> ile; iter(i,1,ile){ int nr, a, b; cin >> nr >> a >> b; a-=b; if(WE[a] == 0 && NS[a] == 0) skrz.pb(a); if(nr == 1) NS[a] ++; else WE[a] ++; } iter(i,0,skrz.size()-1) { sum += min(NS[skrz[i]], WE[skrz[i]]); } cout << sum << "\n"; }
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 | //Samochody Dostawcze #include <bits/stdc++.h> using namespace std; //--------------------------------------------// #define f first #define s second #define mp make_pair #define pb push_back #define all(x) x.begin(),x.end() #define iter(i, a, b) for(int (i)=(a);i<=(b);(i)++) #define iterl(i, a, b) for(int (i)=(a);i>=(b);(i)--) #define upgrade ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0) #define erase_dupl(x) sort(all(x));(x).resize(distance((x).begin(), unique(all(x)))) #define ll long long #define cll const ll #define cint const int #define pll pair<ll,ll> #define pil pair<int,ll> #define pli pair<ll,int> #define pii pair<int,int> //--------------------------------------------// unordered_map<int,int> WE; unordered_map<int,int> NS; vector<int> skrz; int sum; int main(){ upgrade; int ile; cin >> ile; iter(i,1,ile){ int nr, a, b; cin >> nr >> a >> b; a-=b; if(WE[a] == 0 && NS[a] == 0) skrz.pb(a); if(nr == 1) NS[a] ++; else WE[a] ++; } iter(i,0,skrz.size()-1) { sum += min(NS[skrz[i]], WE[skrz[i]]); } cout << sum << "\n"; } |