# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
936332 |
2024-03-01T15:51:16 Z |
8pete8 |
Schools (IZhO13_school) |
C++17 |
|
89 ms |
35092 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);
}
int del[mxn+10];
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<pii>q1,q2;
while(cur<min(n,a)){
ans+=v[cur].f;
q1.push({v[cur].s-v[cur].f,cur});
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();
while(!q1.empty()&&del[q1.top().s])q1.pop();
while(del[cur]&&cur<n)cur++;
if(!q1.empty())cost1=q1.top().f+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}),cur++;
}
else{
del[q2.top().s]=1;
ans+=cost2;
q2.pop();
}
}
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
}
if we take b we cant change it back?
will greedy work?
*/
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 |
1 ms |
464 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
604 KB |
Output is correct |
8 |
Correct |
1 ms |
604 KB |
Output is correct |
9 |
Correct |
2 ms |
584 KB |
Output is correct |
10 |
Correct |
2 ms |
740 KB |
Output is correct |
11 |
Correct |
2 ms |
604 KB |
Output is correct |
12 |
Correct |
2 ms |
860 KB |
Output is correct |
13 |
Correct |
9 ms |
2344 KB |
Output is correct |
14 |
Runtime error |
28 ms |
12176 KB |
Execution killed with signal 11 |
15 |
Runtime error |
54 ms |
23112 KB |
Execution killed with signal 11 |
16 |
Runtime error |
53 ms |
24332 KB |
Execution killed with signal 11 |
17 |
Runtime error |
70 ms |
28736 KB |
Execution killed with signal 11 |
18 |
Runtime error |
69 ms |
29148 KB |
Execution killed with signal 11 |
19 |
Runtime error |
74 ms |
29384 KB |
Execution killed with signal 11 |
20 |
Runtime error |
89 ms |
35092 KB |
Execution killed with signal 11 |