Submission #693616

#TimeUsernameProblemLanguageResultExecution timeMemory
693616zeroesandonesSolar Storm (NOI20_solarstorm)C++17
10 / 100
207 ms42288 KiB
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<ll> vi;
typedef pair<ll, ll> pi;

#define FOR(i, j, k) for (ll i = j; i < (ll) k; ++i)
#define FORD(i, j, k) for (ll i = j; i >= (ll) k; --i)
#define nl "\n"
#define sp " "

#define all(x) (x).begin(), (x).end()
#define sc second
#define fr first
#define pb emplace_back

void solve()
{
    // done : 1, 2, 4
    // trial at subtask 3
    // idea for subtask 5:
    // for every range, check if this range can be covered
    // might be binary search check if this value can be achieved
    ll n, s, k;
    cin >> n >> s >> k;

    ll d[n - 1];
    FOR(i, 0, n - 1)
        cin >> d[i];

    ll a[n];
    FOR(i, 0, n)
        cin >> a[i];

    ll psum[n] = {};
    psum[0] = a[0];
    FOR(i, 1, n)
        psum[i] = psum[i - 1] + a[i];

    ll pos[n] = {};
    pos[0] = 0;
    for(int i = 1; i < n; ++i) {
        pos[i] = pos[i - 1] + d[i - 1];
    }

    vi left(n, 0), right(n, 0);
    for(int i = 0; i < n; ++i) {
        ll req = pos[i] - k;
        auto it = lower_bound(pos, pos + n, req) - pos;
        left[i] = it;
        req = pos[i] + k + 1;
        it = upper_bound(pos, pos + n, req) - pos;
        right[i] = it - 1;
    }

    pi ans = {0, 0};
    for(int i = 0; i < n; ++i) {
        // the only module will be placed here
        ll curr = psum[right[i]] - (left[i] == 0 ? 0 : psum[left[i] - 1]);
        if(curr > ans.fr) {
            ans = {curr, i};
        }
    }

    cout << 1 << nl;
    cout << ans.sc + 1 << nl;
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll t = 1;
    // cin >> t;
    while (t--)
    {
        solve();
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...