#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, k, l;
int counter = 0;
cin >> n;
int a, b, c;
pair<int, int> temp;
vector<int> AutaPion(n);
vector<int> AutaPoziom(n);
k=0;
l=0;
for(int i=0; i<n; i++)
{
cin >> a >> b >> c;
if(a%2==0)
AutaPion[k++]=c-b;
else
AutaPoziom[l++]=c-b;
}
AutaPion.resize(k);
AutaPoziom.resize(l);
sort(AutaPion.begin(), AutaPion.end());
sort(AutaPoziom.begin(), AutaPoziom.end());
k=0;
l=0;
int d;
while(k<AutaPion.size()&&l<AutaPoziom.size())
{
if(AutaPion[k]<AutaPoziom[l])
{
k++;
continue;
}
if(AutaPion[k]>AutaPoziom[l])
{
l++;
continue;
}
if(AutaPion[k]==AutaPoziom[l])
{
a=0;
b=l;
while(b<AutaPoziom.size()&&AutaPoziom[b]==AutaPion[k])
{
a++;
b++;
}
c=0;
d=k;
while(d<AutaPion.size()&&AutaPion[d]==AutaPoziom[l])
{
c++;
d++;
}
k=d;
l=b;
if(a<c)
counter+=a;
else
counter+=c;
}
}
cout << counter;
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 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 | #include<iostream> #include<vector> #include<algorithm> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n, k, l; int counter = 0; cin >> n; int a, b, c; pair<int, int> temp; vector<int> AutaPion(n); vector<int> AutaPoziom(n); k=0; l=0; for(int i=0; i<n; i++) { cin >> a >> b >> c; if(a%2==0) AutaPion[k++]=c-b; else AutaPoziom[l++]=c-b; } AutaPion.resize(k); AutaPoziom.resize(l); sort(AutaPion.begin(), AutaPion.end()); sort(AutaPoziom.begin(), AutaPoziom.end()); k=0; l=0; int d; while(k<AutaPion.size()&&l<AutaPoziom.size()) { if(AutaPion[k]<AutaPoziom[l]) { k++; continue; } if(AutaPion[k]>AutaPoziom[l]) { l++; continue; } if(AutaPion[k]==AutaPoziom[l]) { a=0; b=l; while(b<AutaPoziom.size()&&AutaPoziom[b]==AutaPion[k]) { a++; b++; } c=0; d=k; while(d<AutaPion.size()&&AutaPion[d]==AutaPoziom[l]) { c++; d++; } k=d; l=b; if(a<c) counter+=a; else counter+=c; } } cout << counter; return 0; } |
English