# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1112906 | 0pt1mus23 | 학교 설립 (IZhO13_school) | C++14 | 82 ms | 14464 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define ins insert
#define pii pair<int,int>
#define pb push_back
#define endl '\n'
#define putr(x) cout<<x<<endl;return;
#define all(x) x.begin(),x.end()
const int mod = 1e9 +7, sze = 2e5 +23, inf = LLONG_MAX, LG = 20;
void fast(){
int n,m,s;
cin>>n>>m>>s;
vector<pii> arr(n+1);
for(int i =1;i<=n;i++){
cin>>arr[i].first>>arr[i].second;
}
sort(arr.begin()+1,arr.end(),[&](pii a,pii b){
return a.second - a.first < b.second - b.first;
});
vector<int> pref(n+10,0),suff(n+10,0);
int ans=0,pf=0;
priority_queue<int,vector<int>,greater<int>> q;
for(int i =1;i<=n;i++){
pf+=arr[i].first;
q.push(arr[i].first);
if(q.size()>m){
pf-=q.top();
q.pop();
}
pref[i]=pf;
}
while(!q.empty()) q.pop();
int sfa =0;
for(int i = n;i>=1;i--){
sfa+=arr[i].second;
q.push(arr[i].second);
if(q.size()>s){
sfa-=q.top();
q.pop();
}
suff[i]=sfa;
}
for(int i=1;i<=n;i++){
ans=max(ans,pref[i]+suff[i+1]);
}
putr(ans);
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int tt = 1;
// cin>>tt;
while(tt--){
fast();
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |