# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
173431 | 2020-01-04T05:43:04 Z | juggernaut | 학교 설립 (IZhO13_school) | C++14 | 277 ms | 17580 KB |
//Just try and the idea will come! #include<bits/stdc++.h> #define int long long int using namespace std; int n,i,a,b,pr[300001],sf[300001],sum; pair<int,int>p[300001]; multiset<int>st; bool cmp(pair<int,int>l,pair<int,int>r){ return l.first-l.second>r.first-r.second; } main(){ scanf("%lld%lld%lld",&n,&a,&b); for(i=1;i<=n;i++)scanf("%lld%lld",&p[i].first,&p[i].second); sort(p+1,p+1+n,cmp); for(i=1;i<=n;i++){ sum+=p[i].first; st.insert(p[i].first); if(i>a){ sum-=*st.begin(); st.erase(st.begin()); } pr[i]=sum; } st.clear(); sum=0; for(i=n;i>0;i--){ sum+=p[i].second; st.insert(p[i].second); if(n+1>b+i){ sum-=*st.begin(); st.erase(st.begin()); } sf[i]=sum; } sum=0; for(i=a;i<=n-b;i++)sum=max(sum,pr[i]+sf[i+1]); printf("%lld",sum); }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Correct | 2 ms | 380 KB | Output is correct |
3 | Correct | 2 ms | 376 KB | Output is correct |
4 | Correct | 2 ms | 376 KB | Output is correct |
5 | Correct | 1 ms | 376 KB | Output is correct |
6 | Correct | 2 ms | 376 KB | Output is correct |
7 | Correct | 4 ms | 632 KB | Output is correct |
8 | Correct | 5 ms | 760 KB | Output is correct |
9 | Correct | 5 ms | 760 KB | Output is correct |
10 | Correct | 5 ms | 760 KB | Output is correct |
11 | Correct | 5 ms | 636 KB | Output is correct |
12 | Correct | 5 ms | 760 KB | Output is correct |
13 | Correct | 31 ms | 3320 KB | Output is correct |
14 | Correct | 54 ms | 4628 KB | Output is correct |
15 | Correct | 83 ms | 7544 KB | Output is correct |
16 | Correct | 178 ms | 15476 KB | Output is correct |
17 | Correct | 220 ms | 14668 KB | Output is correct |
18 | Correct | 229 ms | 14900 KB | Output is correct |
19 | Correct | 241 ms | 15832 KB | Output is correct |
20 | Correct | 277 ms | 17580 KB | Output is correct |