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

#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)
using namespace std;
auto start = chrono::steady_clock::now();
void init_code(){
    fast_io;
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif 
}
int main(){
    init_code();
    long long n,x,t,sum_dig;
    cin>>n>>x>>t;
    sum_dig=x;
    vector<long long> d(n);
    for(int i=0;i<n;i++){
        cin>>d[i];
        sum_dig+=d[i];
    }
    long long l=t%sum_dig;
    sort(d.begin(),d.end());
    int u=0,k=0;
    while(u+x<l){
        u+=d[k];
        k++;
    }
    if(n!=1)cout<<(k+1)%n;
    else cout<<k+1;
    return 0;
}
Copy
Treasure bbmm
GNU G++17
1 ms
724 KB
Wrong Answer