Submission #374488

#TimeUsernameProblemLanguageResultExecution timeMemory
374488idk321Holiday (IOI14_holiday)C++11
47 / 100
5020 ms6252 KiB
#include"holiday.h"

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

long long int findMaxAttraction(int n, int start, int d, int v[]) {
    if (d == 0) return 0;

    if (start == 0)
    {
        ll res = v[0];
        int a = 0;
        int b = 0;
        ll cur = v[0];
        multiset<int> sett;
        sett.insert(v[0]);
        int cost = 1;
        for (int i = 1; i < n && i <= d; i++)
        {
            cost += 2;
            cur += v[i];
            sett.insert(v[i]);
            while (cost > d)
            {
                cur -= *sett.begin();
                sett.erase(sett.begin());
                cost--;
            }

            res = max(res, cur);
        }

        return res;
    } else
    {
        ll res = v[start];
        multiset<int> sett;
        ll cur = 0;
        for (int i = start; i < n && i - start <= d; i++)
        {


            cur += v[i];
            sett.insert(v[i]);
            int cost = i - start + sett.size();
            while (cost > d && !sett.empty())
            {
                cur -= *sett.begin();
                sett.erase(sett.begin());
                cost--;
            }
            res = max(res, cur);

            multiset<int> csett = sett;
            ll ccur = cur;
            for (int j = start - 1; j >= 0; j--)
            {

                ccur += v[j];
                csett.insert(v[j]);
                int ccost = i - start + start - j + min(i - start, start - j) + csett.size();
                while (ccost > d && !csett.empty())
                {
                    ccur -= *csett.begin();
                    csett.erase(csett.begin());
                    ccost--;
                }

                res = max(res, ccur);
            }
        }

        return res;
    }
    return 0;
}

/*
5 2 2
1000 2 3 4 1000
*/

Compilation message (stderr)

holiday.cpp: In function 'long long int findMaxAttraction(int, int, int, int*)':
holiday.cpp:13:13: warning: unused variable 'a' [-Wunused-variable]
   13 |         int a = 0;
      |             ^
holiday.cpp:14:13: warning: unused variable 'b' [-Wunused-variable]
   14 |         int b = 0;
      |             ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...