#include <iostream>
#include <algorithm>
using namespace std;
int ile,typ,garaz,czas;
int l=0;
int k=0;
int i2;
int typ1[10000001];
int typ2[10000001];
int ilosctyp1;
int ilosctyp2;
int wynik=0;
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>ile;
for(int i=0; i<ile; i++)
{
cin>>typ>>garaz>>czas;
if(typ==1)
{
typ1[l]=garaz-czas;
l++;
}
if(typ==2)
{
typ2[k]=garaz-czas;
k++;
}
}
sort(typ1,typ1+l);
sort(typ2,typ2+k);
int i1=0;
int i2=0;
typ1[l]=2000000;
typ2[k]=2000000;
for(; i1<l&&i2<k;)
{
ilosctyp1=1;
ilosctyp2=1;
if(typ1[i1]==typ2[i2])
{
for(; typ1[i1]==typ1[i1+1];)
{
ilosctyp1++;
i1++;
}
i1++;
for(; typ2[i2]==typ2[i2+1];)
{
ilosctyp2++;
i2++;
}
i2++;
if(ilosctyp1<ilosctyp2)
wynik=wynik+ilosctyp1;
else
wynik=wynik+ilosctyp2;
}
else
{
if(typ1[i1]<typ2[i2])
i1++;
else
i2++;
}
}
cout<<wynik;
}
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 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | #include <iostream> #include <algorithm> using namespace std; int ile,typ,garaz,czas; int l=0; int k=0; int i2; int typ1[10000001]; int typ2[10000001]; int ilosctyp1; int ilosctyp2; int wynik=0; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin>>ile; for(int i=0; i<ile; i++) { cin>>typ>>garaz>>czas; if(typ==1) { typ1[l]=garaz-czas; l++; } if(typ==2) { typ2[k]=garaz-czas; k++; } } sort(typ1,typ1+l); sort(typ2,typ2+k); int i1=0; int i2=0; typ1[l]=2000000; typ2[k]=2000000; for(; i1<l&&i2<k;) { ilosctyp1=1; ilosctyp2=1; if(typ1[i1]==typ2[i2]) { for(; typ1[i1]==typ1[i1+1];) { ilosctyp1++; i1++; } i1++; for(; typ2[i2]==typ2[i2+1];) { ilosctyp2++; i2++; } i2++; if(ilosctyp1<ilosctyp2) wynik=wynik+ilosctyp1; else wynik=wynik+ilosctyp2; } else { if(typ1[i1]<typ2[i2]) i1++; else i2++; } } cout<<wynik; } |
English