Hi. My code runs on my machine for the test cases I tried, but it gives WA
on the google playground. Please help me identify if I'm missing something.
import java.util.*;
public class Solution {
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter no of test cases : ");
int t = sc.nextInt();
int a = 1;
do
{
System.out.println("Enter no of houses");
int houses = sc.nextInt(); //17 slices
System.out.println("enter budget");
long b = sc.nextInt();
int A[] = new int[houses];
for(int i = 0 ; i < houses ; i++)
{
A[i] = sc.nextInt(); //house prices
}
for(int i = 0 ; i < houses ; i++)
{
for(int j = 0 ; j < houses-i-1 ; j++)
{
if(A[j]>A[j+1])
{
int temp = A[j+1];
A[j+1] = A[j];
A[j] = temp;
}
}
}
int k = 0;
int sum = 0;
ArrayList <Integer> ans = new ArrayList <Integer>();
while(sum+A[k] <= b)
{
sum+=A[k];
ans.add(A[k]);
k++;
}
System.out.println(String.format("Case #%d: %d" ,a, ans.size()));
System.out.flush();
a++;
t--;
}while(t!=0);
}
}
Would really appreciate your help, thanks!!! Also, how do you accept input
from the judge system? This was another doubt I had.
--
You received this message because you are subscribed to the Google Groups
"Google Code Jam" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/google-code/06bf87c2-b881-4e5c-9663-bbe8b1f495ef%40googlegroups.com.