#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define lo long long
#define inf 1000000000
#define md 1000000007
#define pb push_back
#define li 300005
#define ii pair< pair<lo int,lo int> ,lo int>
using namespace std;
lo int n,m,s,x,y,vis[li],cev,mx;
ii p[li],z[li];
bool cmp(ii a,ii b){
if(a.fi.fi-a.fi.se>b.fi.fi-b.fi.se) return true;
if(a.fi.fi>b.fi.fi) return true;
if(a.fi.fi<b.fi.fi) return false;
return false;
}
bool cmp2(ii a,ii b){
if(a.fi.se-a.fi.fi>b.fi.se-b.fi.fi) return true;
if(a.fi.se>b.fi.se) return true;
if(a.fi.se<b.fi.se) return false;
return false;
}
int main(){
scanf("%lld %lld %lld",&n,&m,&s);
for(int i=1;i<=n;i++){
scanf("%lld %lld",&x,&y);
p[i]=mp(mp(x,y),i);
z[i]=mp(mp(x,y),i);
}
sort(z+1,z+n+1,cmp);
for(int i=1;i<=m;i++){
cev+=z[i].fi.fi;
vis[z[i].se]=1;
}
sort(z+1,z+n+1,cmp2);
int cnt=0;
for(int i=1;i<=n;i++){
//printf("%d %d %d\n",z[i].fi.fi,z[i].fi.se,z[i].se);
if(cnt==s) break;
if(vis[z[i].se]==1) continue;
cnt++;
cev+=z[i].fi.se;
}
mx=cev;
memset(vis,0,sizeof(vis));
cev=0;
sort(z+1,z+n+1,cmp2);
for(int i=1;i<=s;i++){
cev+=z[i].fi.se;
vis[z[i].se]=1;
}
sort(z+1,z+n+1,cmp);
cnt=0;
for(int i=1;i<=n;i++){
//printf("%d %d %d\n",z[i].fi.fi,z[i].fi.se,z[i].se);
if(cnt==m) break;
if(vis[z[i].se]==1) continue;
cnt++;
cev+=z[i].fi.fi;
}
mx=max(mx,cev);
printf("%lld\n",mx);
return 0;
}
Compilation message
school.cpp: In function 'int main()':
school.cpp:27:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld %lld %lld",&n,&m,&s);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
school.cpp:29:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld %lld",&x,&y);
~~~~~^~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
2680 KB |
Output is correct |
2 |
Correct |
4 ms |
2732 KB |
Output is correct |
3 |
Correct |
4 ms |
2804 KB |
Output is correct |
4 |
Incorrect |
4 ms |
2960 KB |
Output isn't correct |
5 |
Runtime error |
7 ms |
5524 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
6 |
Incorrect |
123 ms |
19696 KB |
Output isn't correct |
7 |
Incorrect |
327 ms |
19776 KB |
Output isn't correct |
8 |
Runtime error |
64 ms |
19776 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
9 |
Runtime error |
953 ms |
33888 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
10 |
Runtime error |
190 ms |
33888 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
11 |
Runtime error |
69 ms |
33888 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
12 |
Runtime error |
20 ms |
33888 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
13 |
Execution timed out |
2053 ms |
33888 KB |
Time limit exceeded |
14 |
Execution timed out |
2069 ms |
33888 KB |
Time limit exceeded |
15 |
Execution timed out |
2065 ms |
33888 KB |
Time limit exceeded |
16 |
Execution timed out |
2078 ms |
33888 KB |
Time limit exceeded |
17 |
Execution timed out |
2066 ms |
33888 KB |
Time limit exceeded |
18 |
Execution timed out |
2064 ms |
33888 KB |
Time limit exceeded |
19 |
Execution timed out |
2069 ms |
33888 KB |
Time limit exceeded |
20 |
Execution timed out |
2064 ms |
33888 KB |
Time limit exceeded |