Submission #895804

#TimeUsernameProblemLanguageResultExecution timeMemory
895804vjudge1Rice Hub (IOI11_ricehub)C++17
68 / 100
1038 ms4184 KiB
#include <bits/stdc++.h>
using namespace std;
#define ll long long int

ll psum(int i, int j, vector<ll> prefix) {
    if (i > j) {
        return 0;
    }
    if (i == 0) {
        return prefix[j];
    }
    return prefix[j] - prefix[i - 1];
}

int besthub(int N, int L, int X[], ll B) {
    vector<ll> prefix(N + 1);
    prefix[0] = X[0];
    for (int i = 1; i <= N; i++) {
        prefix[i] = X[i] + prefix[i - 1];
    }
    int ans = 0;
    for (int i = 0, j = 0; i < N; i++) {
        while (j + 1 <= i) {
            int mid = (i + j) / 2;
            ll x = X[mid] * (mid - j + 1) - psum(j, mid, prefix);
            if (mid + 1 <= i) {
                x += psum(mid + 1, i, prefix) - X[mid] * (i - mid);
            }
            if (x <= B) {
                break;
            }
            j++;
        }
        ans = max(ans, i - j + 1);
    }
    return ans;
}

// int main() {
//     ios_base::sync_with_stdio(0);
//     cin.tie(0);
//     cout.tie(0);
//     int R, L;
//     cin >> R >> L;
//     int X[R];
//     for (ll i = 0; i < R; i++) {
//         cin >> X[i];
//     }
//     ll B;
//     cin >> B;
//     cout << besthub(R, L, X, B) << "\n";
// }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...