fork(2) download
  1. #include<iostream>
  2. using namespace std;
  3. int main(){
  4.  
  5. long int n,x,cost[100];
  6. cin>>n>>x;
  7. for(int i=0;i<n;i++)
  8. cin>>cost[i];
  9. int i=0,flag=0,s=0,first;
  10. first=cost[0];
  11. while(i<n)
  12. {
  13. s+=cost[i];
  14. if(s>x){
  15. s-=first;
  16. first++;
  17. }
  18. if(s==x)
  19. {flag=1;
  20. break;}
  21. i++;
  22. }
  23. if(flag==0)
  24. cout<<"no";
  25. else cout<<"yes";
  26. }
  27.  
Runtime error #stdin #stdout 3.24s 2684KB
stdin
Standard input is empty
stdout
Standard output is empty