Submission #1361541

#TimeUsernameProblemLanguageResultExecution timeMemory
1361541branches1029Light Bulbs (EGOI24_lightbulbs)C++20
0 / 100
0 ms344 KiB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int n;
ll x[300005];
ll y[300005];
ll total_users = 0;

ll check(ll K) {
    ll cur_score = 0;
    int t_ptr = 0;
    ll x_rem = x[0];

    ll skip = K;
    for (int s = 0; s < n; s++) {
        ll available_y = y[s];
        if (skip > 0) {
            ll taking = min(skip, available_y);
            available_y -= taking;
            skip -= taking;
        }
        if (available_y == 0) continue;

        while (available_y > 0 && t_ptr < n) {
            if (x_rem == 0) {
                t_ptr++;
                if (t_ptr < n) x_rem = x[t_ptr];
                else break;
                continue;
            }
            ll match = min(available_y, x_rem);
            if (t_ptr < s) cur_score += match;      // Upvote
            else if (t_ptr > s) cur_score -= match; // Downvote
            available_y -= match;
            x_rem -= match;
        }
    }

    ll to_process = K;
    for (int s = 0; s < n && to_process > 0; s++) {
        ll available_y = min(y[s], to_process);
        to_process -= available_y;
        if (available_y == 0) continue;

        while (available_y > 0 && t_ptr < n) {
            if (x_rem == 0) {
                t_ptr++;
                if (t_ptr < n) x_rem = x[t_ptr];
                else break;
                continue;
            }
            ll match = min(available_y, x_rem);
            if (t_ptr < s) cur_score += match;
            else if (t_ptr > s) cur_score -= match;
            available_y -= match;
            x_rem -= match;
        }
    }
    return cur_score;
}

int main() {
    ios::sync_with_stdio(0); cin.tie(0);

    if (!(cin >> n)) return 0;
    for (int i = 0; i < n; i++) cin >> x[i];
    for (int i = 0; i < n; i++) {
        cin >> y[i];
        total_users += y[i];
    }

    ll ans=-1e9;
    for( int i=0 ; i<total_users ; i++ ){
        ans=max( ans, check(i) );
    }

    cout << ans << endl;

    return 0;
}
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...