# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
90751 | YottaByte | Schools (IZhO13_school) | C++14 | 2070 ms | 9000 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 <algorithm>
#include <iostream>
#include <queue>
using namespace std;
#define pb push_back
#define mk make_pair
#define fr first
#define sc second
#define ll long long
#define int long long
#define pii pair < int, int >
const int N = 3e5 + 1;
vector < pii > v;
ll ans;
int u[N];
main()
{
int n, m, s;
cin >> n >> m >> s;
for(int i = 1; i <= n; i++)
{
int a, b;
cin >> a >> b;
v.pb( {a, b} );
ans += a;
}
if(m + s == 0)
{
cout << 0 << endl;
return 0;
}
int cnt = n - m - s;
while(s--)
{
int mx = (int)1e8, id = -1;
mx = -mx;
for(int i = 0; i < n; i++)
{
if(u[i] == 0)
{
if(mx < v[i].sc - v[i].fr)
{
mx = v[i].sc - v[i].fr;
id = i;
}
}
}
//cout << id << endl;
u[id] = 1;
ans += mx;
}
while(cnt--)
{
int mn = (int)1e8, id = -1;
for(int i = 0; i < n; i++)
{
if(u[i] == 0)
{
if(mn > v[i].fr)
{
mn = v[i].fr;
id = i;
}
}
}
//cout << id << endl;
u[id] = 1;
ans -= mn;
}
cout << ans << endl;
}
/*
3 1 1
5 2
4 1
6 4
7 2 3
9 8
10 6
3 5
1 7
5 7
6 3
5 4
*/
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |