Submission #936324

# Submission time Handle Problem Language Result Execution time Memory
936324 2024-03-01T15:26:00 Z 8pete8 Schools (IZhO13_school) C++17
20 / 100
84 ms 16760 KB
#include<iostream>
#include<stack>
#include<map>
#include<vector>
#include<string>
#include<unordered_map>
#include <queue>
#include<cstring>
#include<cassert>
#include<limits.h>
#include<cmath>
#include<set>
#include<numeric> //gcd(a,b)
#include<algorithm>
#include<bitset> 
#include<stack>
using namespace std;
#define ll long long
#define f first
#define endl "\n"
#define s second
#define pii pair<int,int>
#define pppiiii pair<pii,pii>
#define ppii pair<int,pii>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define pb push_back
//#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define fastio ios::sync_with_stdio(false);cin.tie(NULL);
#pragma GCC optimize ("03,unroll-loops")
#define int long long
const int mod=1e9+7,mxn=5e4,inf=1e18,minf=-1e18,Mxn=2e6,lg=17;
void setIO(string name){
	ios_base::sync_with_stdio(0); cin.tie(0);		
	freopen((name+".in").c_str(),"r",stdin);		
	freopen((name+".out").c_str(),"w",stdout);	
}	
int32_t main(){
	fastio
	int n,a,b;cin>>n>>a>>b;
	int ans=0;
	vector<pii>v(n);
	for(int i=0;i<n;i++)cin>>v[i].f>>v[i].s;
	sort(rall(v));
	v.pb({0,0});
	int cur=0;
	priority_queue<int>q1;
	priority_queue<pii>q2;
	while(cur<min(n,a)){
		ans+=v[cur].f;
		q1.push(v[cur].s-v[cur].f);
		cur++;
	}
	for(int i=cur;i<n;i++)q2.push({v[i].s,i});
	for(int i=0;i<b;i++){
		int cost1=minf,cost2=minf;
		while(!q2.empty()&&q2.top().s<cur)q2.pop();
		if(!q1.empty())cost1=q1.top()+v[cur].f;
		if(!q2.empty())cost2=q2.top().f;
		if(cost1<=0&&cost2<=0)break;
		if(cost1>cost2){
			q1.pop();
			ans+=cost1;
			if(cur<n)q1.push(v[cur].s-v[cur].f),cur++;
		}
		else{
			q2.pop();
			ans+=cost2;
		}
	}
	cout<<ans;
}
/*
we take the first m best cities
then we need to take s more
if s is outside the set
then we can just take the s
or else we can s-m+the current top m that is left
the current top m->a constant
sort (s-m)? then greedy take m then greedy swap to s?
problems{
	sorting by s-m->but the in set and not in set will also affected
	so if in the set the cost of change would be curtopm+s-m{
		this will also make the curtopm be in set m
		which we can changed later?
	}
	if not the cost of change would be s
}
*/

Compilation message

school.cpp: In function 'void setIO(std::string)':
school.cpp:37:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   37 |  freopen((name+".in").c_str(),"r",stdin);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
school.cpp:38:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |  freopen((name+".out").c_str(),"w",stdout);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 1 ms 348 KB Output isn't correct
5 Incorrect 0 ms 344 KB Output isn't correct
6 Incorrect 0 ms 344 KB Output isn't correct
7 Incorrect 1 ms 604 KB Output isn't correct
8 Incorrect 2 ms 468 KB Output isn't correct
9 Incorrect 1 ms 604 KB Output isn't correct
10 Incorrect 2 ms 584 KB Output isn't correct
11 Incorrect 2 ms 604 KB Output isn't correct
12 Incorrect 2 ms 600 KB Output isn't correct
13 Incorrect 9 ms 1944 KB Output isn't correct
14 Incorrect 22 ms 5748 KB Output isn't correct
15 Correct 40 ms 13460 KB Output is correct
16 Incorrect 64 ms 14540 KB Output isn't correct
17 Incorrect 65 ms 14788 KB Output isn't correct
18 Incorrect 64 ms 14540 KB Output isn't correct
19 Incorrect 72 ms 14968 KB Output isn't correct
20 Incorrect 84 ms 16760 KB Output isn't correct