# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
517019 | amukkalir | Holiday (IOI14_holiday) | C++17 | 5030 ms | 2712 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>
#include "holiday.h"
using namespace std;
typedef long long ll;
const int nax = 20;
int n;
int s, d;
int cost (int l, int r) {
return (r-l) + min(abs(s-l), abs(r-s));
}
bool ok (int mask) {
int l=n, r=0;
for(int i=0; (1<<i)<=mask; i++) {
if(mask & (1<<i)) {
l = min(l, i);
r = max(r, i);
}
}
int travel = (r-l) + min(abs(s-l), abs(r-s));
return travel + __builtin_popcount(mask) <= d;
}
long long int findMaxAttraction(int N, int S, int D, int attraction[]) {
n = N;
s = S;
d = D;
ll ans = 0;
priority_queue<ll, vector<ll>, greater<ll>> pq;
ll sum = 0;
for(int i=s;i<n;i++){
int rem = d - cost(s,i);
if(rem <= 0) break;
sum += attraction[i];
pq.push(attraction[i]);
while(pq.size() > rem) {
sum -= pq.top();
pq.pop();
}
priority_queue<ll, vector<ll>, greater<ll>> q;
q = pq;
ll z = sum;
for(int j=s-1; j>=0; j--) {
rem = d - cost(j, i);
if(rem <= 0) break;
z += attraction[j];
q.push(attraction[j]);
while(q.size() > rem) {
z -= q.top();
q.pop();
}
ans = max(ans, z);
}
ans = max(ans, sum);
}
return ans;
}
/*
*/
Compilation message (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... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |