# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
242454 | joseacaz | Holiday (IOI14_holiday) | C++17 | 5034 ms | 2072 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 <bits/stdc++.h>
#define pb push_back
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpi;
typedef vector<pll> vpl;
ll findMaxAttraction(int N, int start, int d, int a[])
{
int k;
ll ans = 0, sum = 0;
priority_queue<ll> PQ;
//only right
if(start == 0)
{
k = d;
for(int j = 0; j < N; j++)
{
sum += a[j];
PQ.push(-a[j]);
while(PQ.size() > k)
{
sum += PQ.top();
PQ.pop();
}
ans = max(ans, sum);
//cerr << i << " " << j << " " << sum << "\n";
k--;
if(k < 0)
break;
}
return ans;
}
//first left then right
for(int i = start; i >= 0; i--)
{
k = d - (start - i);
sum = 0;
while(!PQ.empty())
PQ.pop();
//cerr << k << "\n";
for(int j = i; j < N; j++)
{
sum += a[j];
PQ.push(-a[j]);
while(PQ.size() > k)
{
sum += PQ.top();
PQ.pop();
}
ans = max(ans, sum);
//cerr << i << " " << j << " " << sum << "\n";
k--;
if(k < 0)
break;
}
}
//first right then left
for(int i = start; i < N; i++)
{
k = d - (i - start);
sum = 0;
while(!PQ.empty())
PQ.pop();
//cerr << k << "\n";
for(int j = i; j >= 0; j--)
{
sum += a[j];
PQ.push(-a[j]);
while(PQ.size() > k)
{
sum += PQ.top();
PQ.pop();
}
//cerr << i << " " << j << " " << sum << "\n";
ans = max(ans, sum);
k--;
if(k < 0)
break;
}
}
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... |