#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
vector<int> t1,t2;
int main()
{std::ios_base::sync_with_stdio(0);
int n;
cin>>n;
for(int i=0;i<n;i++)
{int r,w,t;
cin>>r>>w>>t;
if(r==1)t1.push_back(w-t);
if(r==2)t2.push_back(w-t);
}
sort( t1.begin(), t1.end() );
sort( t2.begin(), t2.end() );
int wynik=0;
while(1)
{ int i=t1.size()-1,j=t2.size()-1;
int licz1=0,licz2=0;
if(t1[i]>t2[j])t1.pop_back();
if(t1[i]<t2[j])t2.pop_back();
if(t1[i]==t2[j])
{
while(t1[i]==t1[i-licz1]&&i-licz1>=0){licz1++; t1.pop_back();}
while(t2[j]==t2[j-licz2]&&j-licz2>=0){licz2++;t2.pop_back();}
wynik+=min(licz1,licz2);
}
if(t1.empty()||t2.empty())break;
}
cout<<wynik;
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 | #include <iostream> #include <algorithm> #include <vector> using namespace std; vector<int> t1,t2; int main() {std::ios_base::sync_with_stdio(0); int n; cin>>n; for(int i=0;i<n;i++) {int r,w,t; cin>>r>>w>>t; if(r==1)t1.push_back(w-t); if(r==2)t2.push_back(w-t); } sort( t1.begin(), t1.end() ); sort( t2.begin(), t2.end() ); int wynik=0; while(1) { int i=t1.size()-1,j=t2.size()-1; int licz1=0,licz2=0; if(t1[i]>t2[j])t1.pop_back(); if(t1[i]<t2[j])t2.pop_back(); if(t1[i]==t2[j]) { while(t1[i]==t1[i-licz1]&&i-licz1>=0){licz1++; t1.pop_back();} while(t2[j]==t2[j-licz2]&&j-licz2>=0){licz2++;t2.pop_back();} wynik+=min(licz1,licz2); } if(t1.empty()||t2.empty())break; } cout<<wynik; return 0; } |
English