fork download
  1. import java.util.Scanner;
  2. class Solution
  3. {
  4. public static void main(String[]args)
  5. {
  6. Scanner s=new Scanner(System.in);
  7. int n=s.nextInt();
  8. for(int i=0;i<n;i++)
  9. {
  10. int total=0,count=0;
  11. int p=s.nextInt();
  12. int q=s.nextInt();
  13. int []a=new int[p];
  14. for(int j=0;j<p;j++)
  15. {
  16. a[j]=s.nextInt();
  17. }
  18. for(int j=0;j<p;j++)
  19. {
  20. if(total+a[j]<=q)
  21. {
  22. total+=a[j];
  23. count++;
  24. }
  25. else
  26. {
  27. break;
  28. }
  29. }
  30. System.out.println(count);
  31. count=0;
  32.  
  33. }
  34. }
  35. }
Success #stdin #stdout 0.18s 56708KB
stdin
3
4 10
5 2 5 2
4 5
2 1 1 1
3 10
11 1 1
stdout
2
4
0