# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
235541 | golazcc83 | 학교 설립 (IZhO13_school) | C++14 | 136 ms | 12784 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 <iostream>
#include <algorithm>
#include <queue>
#include <vector>
#define MINF -1000000000000000000
using namespace std;
typedef long long ll;
const int MAXN = 300001;
int N, M, S;
struct city {
ll a, b;
} c[MAXN];
struct descCompBA{
bool operator()(const city &s1, const city &s2) {
return s1.b - s1.a < s2.b - s2.a;
}
};
bool descCompA(const city &s1, const city &s2) {
if(s1.a != s2.a) return s1.a > s2.a;
return s1.b < s2.b;
}
ll An[MAXN], Bn[MAXN];
int main() {
scanf("%d %d %d", &N, &M, &S);
for(int i = 0; i < N; ++i) {
scanf("%lld %lld", &An[i], &Bn[i]);
c[i].a = An[i];
c[i].b = Bn[i];
}
sort(c, c + N, descCompA);
ll res = 0;
priority_queue<city, vector<city>, descCompBA> pq;
for(int i = 0; i < M; ++i) {
res += c[i].a;
pq.push(c[i]);
}
for(int i = M; i < M + S; ++i) {
city tc = pq.top();
if(c[i].b - c[i].a > tc.b - tc.a)
res += c[i].b;
else {
res += c[i].a + tc.b - tc.a;
pq.pop();
pq.push(c[i]);
}
}
printf("%lld\n", res);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |