#include <bits/stdc++.h>
using namespace std;
int n;
int r, w ,t;
pair<int, int> a[500007];
int licznik[3];
int odp;
void podsumuj(){
odp += min(licznik[1], licznik[2]);
licznik[1] = 0;
licznik[2] = 0;
}
// sumuj(min(x1,x2), min(y1,y2), max(x1,x2), max(y1,y2))
int main(){
iostream::sync_with_stdio(false);
cin.tie(0);
cin >> n;
for(int i =0;i < n;i++){
cin >> r, w, t;
a[i].first = w - t;
a[i].second = r;
}
sort(a, a+n);
//init
licznik[a[0].second]++;
//petla
for(int i = 1; i <n; i++){
if(a[i].first != a[i-1].first)
podsumuj();
licznik[a[i].second]++;
}
podsumuj();
//koniec
cout << odp;
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 <bits/stdc++.h> using namespace std; int n; int r, w ,t; pair<int, int> a[500007]; int licznik[3]; int odp; void podsumuj(){ odp += min(licznik[1], licznik[2]); licznik[1] = 0; licznik[2] = 0; } // sumuj(min(x1,x2), min(y1,y2), max(x1,x2), max(y1,y2)) int main(){ iostream::sync_with_stdio(false); cin.tie(0); cin >> n; for(int i =0;i < n;i++){ cin >> r, w, t; a[i].first = w - t; a[i].second = r; } sort(a, a+n); //init licznik[a[0].second]++; //petla for(int i = 1; i <n; i++){ if(a[i].first != a[i-1].first) podsumuj(); licznik[a[i].second]++; } podsumuj(); //koniec cout << odp; return 0; } |
English