Submission #90825

# Submission time Handle Problem Language Result Execution time Memory
90825 2018-12-24T16:00:14 Z antimirage Schools (IZhO13_school) C++14
100 / 100
269 ms 19420 KB
#include <bits/stdc++.h>

#define pb push_back
#define mk make_pair
#define fr first
#define sc second
#define int long long

using namespace std;

const int N = 3e5 + 5;

int n, x, y;

pair <int, int> a[N];

long long ans;

priority_queue < pair <int, int> > q1, q2; 

set <int> st;

main()
{
	cin >> n >> x >> y;
	
	for (int i = 1; i <= n; i++)
	{
		scanf("%d%d", &a[i].fr, &a[i].sc);
	}
	sort( a + 1, a + n + 1, greater < pair <int, int> >() );
	
	for (int i = 1; i <= x; i++)
		ans += a[i].fr, q1.push( mk(-a[i].fr + a[i].sc, i) );
		
	for (int i = x + 1; i <= n; i++)
		q2.push( mk(a[i].sc, i) ), st.insert(i);
	
	while(y--)
	{
		while (!q2.empty() && !st.count(q2.top().sc) )
			q2.pop();
			
		if ( q2.empty() || (!q1.empty() && q1.top().fr + a[*st.begin()].fr > q2.top().fr ) )
		{
			ans += q1.top().fr + a[*st.begin()].fr;
			q1.pop();
			q1.push( mk( -a[*st.begin() ].fr + a[*st.begin()].sc, *st.begin() ) );
			st.erase(st.begin());
		}
		else 
		{
			ans += q2.top().fr;
			st.erase( q2.top().sc );
			q2.pop();
		}
	}
	cout << ans << endl;
}

Compilation message

school.cpp:23:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main()
      ^
school.cpp: In function 'int main()':
school.cpp:29:35: warning: format '%d' expects argument of type 'int*', but argument 2 has type 'long long int*' [-Wformat=]
   scanf("%d%d", &a[i].fr, &a[i].sc);
                                   ^
school.cpp:29:35: warning: format '%d' expects argument of type 'int*', but argument 3 has type 'long long int*' [-Wformat=]
school.cpp:29:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d", &a[i].fr, &a[i].sc);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 372 KB Output is correct
3 Correct 2 ms 448 KB Output is correct
4 Correct 2 ms 468 KB Output is correct
5 Correct 2 ms 552 KB Output is correct
6 Correct 2 ms 552 KB Output is correct
7 Correct 4 ms 800 KB Output is correct
8 Correct 3 ms 816 KB Output is correct
9 Correct 3 ms 816 KB Output is correct
10 Correct 3 ms 816 KB Output is correct
11 Correct 5 ms 944 KB Output is correct
12 Correct 5 ms 992 KB Output is correct
13 Correct 15 ms 1964 KB Output is correct
14 Correct 61 ms 6992 KB Output is correct
15 Correct 107 ms 13276 KB Output is correct
16 Correct 269 ms 14032 KB Output is correct
17 Correct 183 ms 15564 KB Output is correct
18 Correct 179 ms 16076 KB Output is correct
19 Correct 212 ms 16540 KB Output is correct
20 Correct 238 ms 19420 KB Output is correct