Submission #1277301

#TimeUsernameProblemLanguageResultExecution timeMemory
1277301JohannHoliday (IOI14_holiday)C++20
47 / 100
5083 ms1932 KiB
#include "holiday.h"

#include "bits/stdc++.h"
using namespace std;

#define sz(x) (int)(x.size())

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;

ll go_right(int n, int start, int d, int attraction[])
{
    if (d <= 0)
        return 0;
    priority_queue<ll, vi, greater<ll>> pq;
    ll res = 0;
    ll max_res = 0;
    for (int i = start; i < n; ++i)
    {
        res += attraction[i];
        pq.push(attraction[i]);
        while (!pq.empty() && sz(pq) > d - (i - start))
        {
            res -= pq.top();
            pq.pop();
        }
        max_res = max(max_res, res);
    }
    return max_res;
}

long long int findMaxAttraction(int n, int start, int d, int attraction[])
{
    // subtask 2
    if (start == 0)
        return go_right(n, 0, d, attraction);

    // quadratic brute force
    ll res = 0;
    // one direction
    for (int i = start; i >= 0; --i)
        res = max(res, go_right(n, i, d - (start - i), attraction));
    // other direction
    reverse(attraction, attraction + n);
    start = (n - 1) - start;
    for (int i = start; i >= 0; --i)
        res = max(res, go_right(n, i, d - (start - i), attraction));
    return res;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...