fork download
  1. #include <iostream>
  2. #include <bits/stdc++.h>
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7. // your code goes here
  8. int test;
  9. cin>>test;
  10. while(test!=0){
  11. int n;
  12. int d;
  13. cin>>n;
  14. cin>>d;
  15. int arr[n];
  16. int i=0;
  17. int j=n;
  18. while(j!=0){
  19. int x;
  20. cin>>x;
  21. arr[i]=x;
  22. i++;
  23. j--;
  24. }
  25. int last=1;
  26. while(d!=0 && n>1){
  27. if(arr[last]!=0){
  28. arr[last]--;
  29. arr[(last-1)]++;
  30. if(last>1){
  31. last--;
  32. }
  33. }
  34. else{
  35. for(int k=last+1;k<n;k++){
  36. if(arr[k]>0){
  37. last=k-1;
  38. arr[k]--;
  39. arr[last]++;
  40. break;
  41. }
  42. }
  43. }
  44. d--;
  45. }
  46. cout<<arr[0]<<endl;
  47. test--;
  48. }
  49. return 0;
  50. }
Success #stdin #stdout 0s 4196KB
stdin
Standard input is empty
stdout
-1413362308
-1413362308