islomiddin

title

Jan 11th, 2016
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. import java.util.*;
  2. public class price
  3. {
  4. public static void main(String[] args)
  5. {
  6. Scanner sc=new Scanner(System.in);
  7. int t=sc.nextInt();
  8. for(int i=0;i<t;i++)
  9. {
  10. int n=sc.nextInt();
  11. long p=sc.nextLong();
  12. long[] list=new long[n];
  13. for(int j=0;j<n;j++)
  14. {
  15. list[j]=sc.nextLong();
  16. }
  17. int count=less(list,p);
  18. for(int h=0;h<n-1;h++)
  19. {
  20. for(int m=h+1;m<n;m++)
  21. {
  22. if (sumof(list, h, m)<=p)
  23. count++;
  24. }
  25. }
  26. int f=i+1;
  27. System.out.println("Case "+"#"+f+": "+count);
  28. }
  29. }
  30.  
  31. public static long sumof(long[] list, int a, int b)
  32. {
  33. long sum=0;
  34. for(int i=a;i<=b;i++)
  35. sum=sum+list[i];
  36. return sum;
  37. }
  38.  
  39. public static int less(long[] list, long p)
  40. {
  41. int c=0;
  42. for(int i=0;i<list.length;i++)
  43. {
  44. if(list[i]<=p)
  45. c++;
  46. }
  47. return c;
  48. }
  49. }
Add Comment
Please, Sign In to add comment