Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class price
- {
- public static void main(String[] args)
- {
- Scanner sc=new Scanner(System.in);
- int t=sc.nextInt();
- for(int i=0;i<t;i++)
- {
- int n=sc.nextInt();
- long p=sc.nextLong();
- long[] list=new long[n];
- for(int j=0;j<n;j++)
- {
- list[j]=sc.nextLong();
- }
- int count=less(list,p);
- for(int h=0;h<n-1;h++)
- {
- for(int m=h+1;m<n;m++)
- {
- if (sumof(list, h, m)<=p)
- count++;
- }
- }
- int f=i+1;
- System.out.println("Case "+"#"+f+": "+count);
- }
- }
- public static long sumof(long[] list, int a, int b)
- {
- long sum=0;
- for(int i=a;i<=b;i++)
- sum=sum+list[i];
- return sum;
- }
- public static int less(long[] list, long p)
- {
- int c=0;
- for(int i=0;i<list.length;i++)
- {
- if(list[i]<=p)
- c++;
- }
- return c;
- }
- }
Add Comment
Please, Sign In to add comment