# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
84459 | talip | 학교 설립 (IZhO13_school) | C++14 | 179 ms | 9364 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int N = 300005;
int n, m, q, a[N], b[N], p[N];
long long int f[N], g[N], s, res;
//Memory leak with vector......
//Will test against greater<int>
bool fark(int x, int y) {
return a[x] - b[x] < a[y] - b[y];
}
int main() {
ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
cin >> n >> m >> q;
for (int i = 0; i < n; ++i){
cin >> a[i] >> b[i];
}
for (int i = 0; i < n; ++i){
p[i] = i;
}
sort(p, p + n, fark); priority_queue<int> pq; s = 0;
for(int i = 0; i < n; ++i) {
pq.push(-b[p[i]]); s += b[p[i]];
if (pq.size()>q) {
s += pq.top(); pq.pop();
}
f[i] = s;
}
while(pq.size()){
pq.pop();
}
s = 0;
for(int i=n-1;i>=0;i--){
pq.push(-a[p[i]]); s += a[p[i]];
if (pq.size()>m) {
s+=pq.top(); pq.pop();
}
g[i] = s;
}
for (int i = q - 1; i < n - m; ++i){
res = max(res, f[i] + g[i + 1]);
}
cout << res;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |