#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 |
2684 KB |
Output is correct |
2 |
Correct |
4 ms |
2804 KB |
Output is correct |
3 |
Correct |
4 ms |
2804 KB |
Output is correct |
4 |
Runtime error |
280 ms |
33592 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
5 |
Runtime error |
11 ms |
33592 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
6 |
Runtime error |
277 ms |
33776 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
7 |
Execution timed out |
2050 ms |
33776 KB |
Time limit exceeded |
8 |
Runtime error |
62 ms |
33776 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
9 |
Runtime error |
344 ms |
33776 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
10 |
Runtime error |
32 ms |
33776 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
11 |
Execution timed out |
2062 ms |
33776 KB |
Time limit exceeded |
12 |
Runtime error |
19 ms |
33776 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
13 |
Execution timed out |
2062 ms |
33776 KB |
Time limit exceeded |
14 |
Execution timed out |
2061 ms |
33776 KB |
Time limit exceeded |
15 |
Execution timed out |
2043 ms |
33776 KB |
Time limit exceeded |
16 |
Execution timed out |
2064 ms |
33776 KB |
Time limit exceeded |
17 |
Execution timed out |
2059 ms |
33776 KB |
Time limit exceeded |
18 |
Execution timed out |
2045 ms |
33776 KB |
Time limit exceeded |
19 |
Runtime error |
892 ms |
33900 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
20 |
Execution timed out |
2053 ms |
33900 KB |
Time limit exceeded |