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 <algorithm>
#include <iostream>
#include <numeric>
#include <cassert>
#include <vector>
#include <queue>
typedef long long llong;
const int MAXN = 100000 + 10;
const int INF = 1e9;
int n;
int pos, d;
int a[MAXN];
llong ans;
void rec(int l, int r, int optL, int optR)
{
int opt = -1;
int mid = (l + r) / 2;
std::priority_queue <int> pq;
llong currSum = 0;
llong currRes = 0;
for (int i = mid ; i < optL ; ++i)
{
pq.push(-a[i]);
currSum += a[i];
}
for (int i = optL ; i <= optR && d - pos + 2 * mid - i > 0 ; ++i)
{
pq.push(-a[i]);
currSum += a[i];
while (pq.size() > d - pos + 2 * mid - i)
{
currSum += pq.top();
pq.pop();
}
if (currSum >= currRes)
{
currRes = currSum;
opt = i;
}
}
if (opt == -1)
{
opt = optL;
}
if (l < mid) rec(l, mid - 1, optL, opt);
if (mid < r) rec(mid + 1, r, opt, optR);
ans = std::max(ans, currRes);
}
llong findMaxAttraction(int N, int start, int D, int A[])
{
n = N;
d = D;
pos = start + 1;
for (int i = 1 ; i <= n ; ++i)
{
a[i] = A[i - 1];
}
if (pos <= n) rec(1, pos, pos + 1, n);
std::reverse(a + 1, a + 1 + n);
pos = n - pos + 1;
if (pos <= n) rec(1, pos, pos + 1, n);
return ans;
}
Compilation message (stderr)
holiday.cpp: In function 'void rec(int, int, int, int)':
holiday.cpp:37:26: warning: comparison of integer expressions of different signedness: 'std::priority_queue<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
37 | while (pq.size() > d - pos + 2 * mid - i)
| ~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# | 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... |