2 / 2
May 2022

SP10401 ALIEN - Aliens at the train22
Thank you very much for reading this article.
I am a beginner.I have encountered difficulties in this problem.
This is my code. Who can tell me how to modify it.
Be deeply grateful.

#include<bits/stdc++.h>
using namespace std;
int t,at,bt,atith,peo,sta;
int main(){
cin>>t;
if(t==0){
return 0;
}
for(int i=1;i<=t;i++){
cin>>at>>bt;
for(int j=1;j<=at;j++){
cin>>atith;
peo+=atith;
sta++;
if(peo>=bt){
cout<<peo-atith<<" "<<sta-1<<endl;
break;
}
}
}
return 0;
}

  • created

    May '22
  • last reply

    May '22
  • 1

    reply

  • 635

    views

  • 2

    users

  • 1

    like

  • 1

    link

The question isn’t worded very clearly, but the alien can get on the train at any station, not necessarily the first.