# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
15708 | gs14004 | 휴가 (IOI14_holiday) | C++14 | 0 ms | 0 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"holiday.h"
#include <cstdio>
#include <queue>
#include <algorithm>
using namespace std;
typedef long long lint;
priority_queue<int, vector<int>, greater<int> > pq;
lint ret;
int *a, st, dist;
void divConq(int s, int e, int rs, int re){ // boilerplate
if(s > e) return;
int m = (s+e)/2;
lint copt = 0, cres = -1;
int opt = 0;
for(int i=m; i<rs; i++){
pq.push(a[i]);
copt += a[i];
}
for(int i=rs; i<=re; i++){
pq.push(a[i]);
copt += a[i];
while(!pq.empty() && (int)pq.size() > dist - (i - m + min(i - st, st - m) )){
copt -= pq.top();
pq.pop();
}
if(cres < copt){
cres = copt;
opt = i;
}
}
ret = max(ret, cres);
while(!pq.empty()) pq.pop();
divConq(s,m-1,rs,opt);
divConq(m+1,e,opt,re);
}