# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
90804 | Aydarov03 | Schools (IZhO13_school) | C++14 | 515 ms | 35160 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define ll long long
#define pii pair<ll,ll>
#define fr first
#define sc second
using namespace std;
vector < pii > v;
main()
{
multiset < ll > rz;
multiset < pii> v1 , v2;
ll x , y;
ll n , m , s , ans = 0;
cin >> n >> m >> s;
for(int i = 1; i <= n; i++)
{
cin >> x >> y;
v.push_back( {x , y} );
}
sort( v.rbegin() , v.rend() );
for(int i = 0; i < m; i++)
{
ans += v[i].fr;
rz.insert( (v[i].fr - v[i].sc) );
}
for(int i = m; i < n; i++)
{
v1.insert( v[i] );
v2.insert( {v[i].sc , v[i].fr} );
}
for(int i = s; i >= 1; i--)
{
pii x = *v1.rbegin();
pii y = *v2.rbegin();
int raz = -*rz.begin();
if( x.fr + raz > y.fr )
{
ans += (x.fr + raz);
rz.erase( rz.begin() );
rz.insert( x.fr - x.sc );
v1.erase( v1.find( {x.fr , x.sc}) );
v2.erase( v2.find( {x.sc , x.fr} ) );
}
else
{
ans += y.fr;
v2.erase( v2.find( {y.fr , y.sc } ) );
v1.erase( v1.find( {y.sc , y.fr } ) );
}
}
cout << ans;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |