Submission #714044

#TimeUsernameProblemLanguageResultExecution timeMemory
714044Spade1Rice Hub (IOI11_ricehub)C++14
49 / 100
17 ms2180 KiB
#include <bits/stdc++.h>
#define ll long long
#include "ricehub.h"
//#include "grader.cpp"

using namespace std;

queue<int> qL, qR;

int besthub(int R, int L, int X[], ll B) {
    ll cost = 0, cur = 1;
    int ans = 0;
    for (int i = 0; i < R; ++i) {
        if (i != 0) cost += (X[i]-X[i-1])*qL.size();
        if (i != 0) cost -= (X[i]-X[i-1])*qR.size();
        if (!qR.empty() && qR.front() == X[i]) qR.pop();
        if (cur <= i) cur++;
        qL.push(X[i]);
        while (cost > B) {
            cost -= X[i]-qL.front();
            qL.pop();
        }
        while (cur < R) {
            if (cost + X[cur] - X[i] > B) {
                if (cost - (X[i]-qL.front()) + (X[cur]-X[i]) <= cost) {
                    cost -= X[i]-qL.front();
                    cost += X[cur]-X[i];
                    qL.pop();
                    qR.push(X[cur++]);
                }
                else break;
            }
            else {
                cost += X[cur] - X[i];
                qR.push(X[cur++]);
            }
        }
        int cur = qL.size() + qR.size();
        ans = max(ans, cur);
    }
    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...