QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#428488#8777. Passport Stampssuzukaze_Aobayama (Takehiro Suda, Taishi Amagai, Yoshinori Furuto)#WA 4ms3956kbC++171.0kb2024-06-01 19:49:292024-06-01 19:49:30

Judging History

This is the latest submission verdict.

  • [2024-06-01 19:49:30]
  • Judged
  • Verdict: WA
  • Time: 4ms
  • Memory: 3956kb
  • [2024-06-01 19:49:29]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
#define all(A) A.begin(),A.end()
#define rep(i, n) for (ll i = 0; i < (ll) (n); i++)

int main() {

    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    ll N,P;
    cin>>N>>P;
    vll A(N);
    rep(i,N)cin>>A[i];
    if(A[0]>P){
        cout<<0<<endl;
        return 0;

    }
    ll x=0;
    rep(i,N){
        x+=A[i];
    }
    rep(i,N-1){
        x+=A[N-1]-1;
        if(x>P){
            break;
        }
    }
    if(x+A[N-1]<=P){
        cout<<N<<endl;
        return 0;
    }
    ll L=0,R=N;
    while(R-L>1){
        ll M=(R+L)/2;
        ll x=0;
        rep(j,M+1){
            x+=A[j];
            if(x>P)break;
        }
        if(x<=P){
            if(A[M]-1<=(P-x)/M){

            }
            else{
                x+=(A[M]-1)*M;
            }
        }
        // cout<<M<<" "<<x+A[M]<<" "<<P<<endl;
        if(x<=P)L=M;
        else R=M;
    }
    cout<<R<<endl;
    

}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3528kb

input:

5 15
1
2
3
4
5

output:

3

result:

ok single line: '3'

Test #2:

score: 0
Accepted
time: 4ms
memory: 3956kb

input:

100000 559309580160692839
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
...

output:

84437

result:

ok single line: '84437'

Test #3:

score: -100
Wrong Answer
time: 3ms
memory: 3820kb

input:

100000 890934113082207108
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
...

output:

100000

result:

wrong answer 1st lines differ - expected: '53636', found: '100000'