Submission #1033383

#TimeUsernameProblemLanguageResultExecution timeMemory
1033383onbert휴가 (IOI14_holiday)C++17
100 / 100
53 ms6048 KiB
#include "holiday.h"
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int maxn = 1e5 + 5;
int n, a[maxn];

int solve(int S, int d) {
    int ans = 0, curans = 0;
    priority_queue<pair<int,int>, vector<pair<int,int>>, greater<pair<int,int>>> pq;
    for (int i=S;i<=n;i++) {
        pq.push({a[i], -i}), curans += a[i];
        while (pq.size() > 0 && i-S + pq.size() > d) {
            curans -= pq.top().first;
            pq.pop();
        }
        ans = max(curans, ans);
    }
    while (pq.size() > 0) pq.pop();
    curans = 0;
    priority_queue<int> pq2;
    bool del[n+1];
    for (int i=1;i<=n;i++) del[i] = false;
    for (int i=S;i<=n;i++) {
        pq.push({a[i], -i}), pq2.push(i), curans += a[i];
        while (pq.size() > 0 && i-S + pq.size() > d) {
            pair<int,int> x = pq.top();
            curans -= x.first;
            del[-x.second] = true;
            pq.pop();
        }
        if (curans==ans) break;
    }

    while (pq2.size() > 0) {
        int X = pq2.top();
        if (del[X]) pq2.pop(), del[X] = false;
        else break;
    }
    for (int i=S-1, D = d-1; i>=1 && D>=1; i--, D--) {
        pq.push({a[i], -i}), pq2.push(i), curans += a[i];
        while (pq.size() > 0 && pq2.top()-i + pq.size() > D) {
            pair<int,int> x = pq.top();
            curans -= x.first;
            pq.pop();
            del[-x.second] = true;
            while (pq2.size() > 0) {
                int X = pq2.top();
                if (del[X]) pq2.pop(), del[X] = false;
                else break;
            }
        }
        ans = max(curans, ans);
    }
    return ans;
}
 
int findMaxAttraction(int32_t N, int32_t S, int32_t D, int32_t A[]) {
    n = N, S++;
    for (int i=1;i<=n;i++) a[i] = A[i-1];
    int ans1 = solve(S, D);
    reverse(a+1, a+n+1); S = n+1-S;
    int ans2 = solve(S, D);
    return max(ans1, ans2);
}

Compilation message (stderr)

holiday.cpp: In function 'long long int solve(long long int, long long int)':
holiday.cpp:13:49: warning: comparison of integer expressions of different signedness: 'long long unsigned int' and 'long long int' [-Wsign-compare]
   13 |         while (pq.size() > 0 && i-S + pq.size() > d) {
      |                                 ~~~~~~~~~~~~~~~~^~~
holiday.cpp:26:49: warning: comparison of integer expressions of different signedness: 'long long unsigned int' and 'long long int' [-Wsign-compare]
   26 |         while (pq.size() > 0 && i-S + pq.size() > d) {
      |                                 ~~~~~~~~~~~~~~~~^~~
holiday.cpp:42:57: warning: comparison of integer expressions of different signedness: 'long long unsigned int' and 'long long int' [-Wsign-compare]
   42 |         while (pq.size() > 0 && pq2.top()-i + pq.size() > D) {
      |                                 ~~~~~~~~~~~~~~~~~~~~~~~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...