| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 249457 | dwsc | Cake 3 (JOI19_cake3) | C++14 | 4078 ms | 4736 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define int long long
using namespace std;
typedef pair<int,int> ii;
main(){
int n,m;
cin >> n >> m;
ii arr[n];
for (int i = 0; i < n; i++) cin >> arr[i].second >> arr[i].first;
sort(arr,arr+n);
int ans = -1e18;
for (int i = 0; i+m <= n; i++){
int sum = 0;
priority_queue<int,vector<int>,greater<int> > pq;
for (int j = i; j < i+m; j++){
pq.push(arr[j].second);
sum += arr[j].second;
}
ans = max(ans,sum-2*(arr[i+m-1].first-arr[i].first));
for (int j = i+m; j < n; j++){
int v = arr[j].second;
if (v > pq.top()){
sum += v-pq.top();
pq.pop();
pq.push(v);
ans = max(ans,sum-2*(arr[j].first-arr[i].first));
}
}
}
cout << ans;
}
컴파일 시 표준 에러 (stderr) 메시지
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
