# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
676583 | QwertyPi | Schools (IZhO13_school) | C++14 | 195 ms | 10460 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
struct area{
int a, b;
};
int main(){
int N, M, S;
cin >> N >> M >> S;
vector<area> A;
for(int i = 0; i < N; i++){
int a, b; cin >> a >> b;
A.push_back({a, b});
}
sort(A.begin(), A.end(), [](area x, area y){
return x.a > y.a;
});
int ans = 0;
for(int i = 0; i < M; i++){
ans += A[i].a;
}
priority_queue<pair<int, int>> pq1, pq2;
for(int i = 0; i < M; i++){
pq1.push({A[i].b - A[i].a, i});
}
for(int i = M; i < N; i++){
pq2.push({A[i].b, i});
}
for(int i = 0; i < S; i++){
if(pq2.empty() || !pq1.empty() && pq1.top().first + A[M + i].a > pq2.top().first){
ans += pq1.top().first + A[M + i].a;
pq1.pop();
}else{
ans += pq2.top().first;
pq2.pop();
}
}
cout << ans << endl;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |