Submission #242451

#TimeUsernameProblemLanguageResultExecution timeMemory
242451joseacazHoliday (IOI14_holiday)C++17
24 / 100
5064 ms2172 KiB
#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[])
{
    //first left then right
    int k;
    ll ans = 0, sum = 0;
    priority_queue<ll> PQ;
    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)

holiday.cpp: In function 'll findMaxAttraction(int, int, int, int*)':
holiday.cpp:34:29: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             while(PQ.size() > k)
                   ~~~~~~~~~~^~~
holiday.cpp:59:29: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             while(PQ.size() > k)
                   ~~~~~~~~~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...