Source Code
#include <bits/stdc++.h>
 
#define F first
#define S second
#define endl '\n'
#define em emplace_back
#define all(x) (x).begin(),(x).end()
#define IOS ios_base::sync_with_stdio(false);cin.tie(0); cout.tie(0)
 
using namespace std;
 
using ll=long long;
using ii=pair<int,int>;


int main() {
#ifdef LOCAL
    freopen("input.in","r",stdin);
#endif
    IOS;
    int t=1;
    // cin>>t;
    while(t--){
        int n;
        cin>>n;
        ll x,tot;
        cin>>x>>tot;
        vector<int>d(n);
        for(auto &i:d){
            cin>>i;
        }
        ll sum=accumulate(all(d),0ll);
        sum+=x;
        if(tot>sum){
            tot%=sum;
        }
        int ans=0;
        if(tot==0)ans++;
        for(int i=0;i<n;++i){
            if(tot>0 && x>=tot){
                ans++;
            }
            tot-=d[i];
        }
        if(tot>0 && x>=tot){
            ans++;
        }
        cout<<ans<<endl;
    }
#ifdef LOCAL
    cerr << "\nTime elapsed: " << (1.0 * clock()) / CLOCKS_PER_SEC << " s.\n";
#endif
    return 0;
}
Copy
Treasure omar94
GNU G++17
15 ms
1.6 MB
Accepted