Source Code
#include "bits/stdc++.h"

#pragma GCC optimize("Ofast")
#pragma GCC optimize("-O2")

using namespace std;
using ll = long long;
using ld = long double;

int dx[] = {1, -1, 0, 0, -1, -1, 1, 1};
int dy[] = {0, 0, 1, -1, -1, 1, -1, 1};

const int N = 2E5 + 5, M = 2E6 + 10, MOD = 1E9 + 7, OO = 0x3f3f3f3f;
ll n, x, t, d[N], pref[N], ans, s;

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

    cin >> n >> x >> t;
    for (int i = 1; i <= n; ++i)
        cin >> d[i], pref[i] = d[i] + pref[i-1];

    for (int i = 0; i <= n; ++i)
        if(pref[i] < t && pref[i] + x >= t) ans++;

    if(ans == 0 && pref[n] < t){
        int l = 0, r = t / pref[n], mid;
        while (l <= r){
            mid = (l + r) / 2;
            if(mid * (x + pref[n]) < t)
                s = mid, l = mid + 1;
            else
                r = mid - 1;
        }

        s *= (pref[n] + x);
        for (int i = 0; i <= n; ++i) {
            pref[i] += s;
            if (pref[i] < t && pref[i] + x >= t) ans++;
        }
    }

    cout << ans;

    return 0;
}
Copy
Treasure Redhwan
GNU G++17
16 ms
3.9 MB
Wrong Answer