Source Code
#include <bits/stdc++.h>

using namespace std;

#define modulo ll (1e9 + 7)
#define neig(a, u, e, v) for(int v, e = (a).head[u] ; ~e and (v = (a).to[e], 1) ; e = (a).nxt[e])

typedef long long ll;

const int N = 2e5 + 9, M = 1e6 + 9, OO = 0x3f3f3f3f;
const ll llOO = 0x3f3f3f3f3f3f3f3f;

bool overflow(ll a, ll b) {
    if(b == 0)  return 0;
    return (a > LLONG_MAX / b);
}

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

    ll n, x, t;
    cin >> n >> x >> t;

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

    ll ans = 0;
    for(int i = 0;i <= n;i++){
        ll prefix = d[i] + x;
        ll suffix = d[n] - d[i];

        ll l = 1, r = t;
        while(l <= r){
            ll mid = (l + r) >> 1;


            if(overflow(prefix, mid) || overflow(suffix, mid - 1)) {
                r = mid - 1;
                continue;
            }

            ll rem = t - (prefix * mid + suffix * (mid - 1));

            if(rem <= 0)
                r = mid - 1;
            else
                l = mid + 1;
        }

        ll rem1 = t - (prefix * l - x + suffix * (l - 1));
        ll rem2 = t - (prefix * l + suffix * (l - 1));
        if(l > 0 && rem1 > 0 && rem2 <= 0)
            ans++;
    }

    cout << ans;
}
Copy
Treasure Muhammad
GNU G++17
1 ms
872 KB
Wrong Answer