Submission #90823

#TimeUsernameProblemLanguageResultExecution timeMemory
90823antimirageSchools (IZhO13_school)C++14
15 / 100
255 ms18816 KiB
#include <bits/stdc++.h>
  
#define fr first
#define sc second
#define mk make_pair
#define pb emplace_back
#define all(s) s.begin(), s.end()
#define int long long
 
using namespace std;

const int N = 3e5 + 5;

int n, x, y, a[N], b[N];

long long ans;

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

set <int> st;

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

Compilation message (stderr)

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:27:29: warning: format '%d' expects argument of type 'int*', but argument 2 has type 'long long int*' [-Wformat=]
   scanf("%d%d", &a[i], &b[i]);
                 ~~~~~       ^
school.cpp:27:29: warning: format '%d' expects argument of type 'int*', but argument 3 has type 'long long int*' [-Wformat=]
school.cpp:27:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d", &a[i], &b[i]);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...