Submission #90751

#TimeUsernameProblemLanguageResultExecution timeMemory
90751YottaByteSchools (IZhO13_school)C++14
20 / 100
2070 ms9000 KiB
#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)

school.cpp:21:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main()
      ^
#Verdict Execution timeMemoryGrader output
Fetching results...