제출 #281806

#제출 시각아이디문제언어결과실행 시간메모리
281806SamAndHoliday (IOI14_holiday)C++17
24 / 100
5053 ms6712 KiB
#include"holiday.h"
#include <bits/stdc++.h>
using namespace std;
#define m_p make_pair
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
typedef long long ll;
const int N = 100005;

int n;
int a[N];

long long int findMaxAttraction(int n, int start, int d, int attraction[])
{
    ::n = n;
    for (int i = 0; i < n; ++i)
        a[i] = attraction[i];

    ll ans = 0;

    for (int u = start; u < n; ++u)
    {
        ll yans = 0;
        multiset<int> s;
        for (int i = start; i <= u; ++i)
        {
            s.insert(a[i]);
            yans += a[i];
        }
        while (!s.empty() && sz(s) > d - (u - start))
        {
            yans -= (*s.begin());
            s.erase(s.begin());
        }
        for (int i = start; i >= 0; --i)
        {
            if (i < start)
            {
                s.insert(a[i]);
                yans += a[i];
            }
            while (!s.empty() && sz(s) > d - (2 * min(start - i, u - start) + max(start - i, u - start)))
            {
                yans -= (*s.begin());
                s.erase(s.begin());
            }
            ans = max(ans, yans);
        }
    }
    return ans;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...