Google kick Start 2020 Round A Allocation problem In java

245 views Asked by At

Anyone please help me out to solve this problem in java As I have tried with following code

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.Arrays;

public class Solution1 {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(System.out));
        long testCases = Integer.parseInt(br.readLine());
        int n;
        long b;
        int[] a;
        int count;
        for (int i = 1; i <= testCases; i++) {
            String[] inputs = br.readLine().split(" ");
            n = Integer.parseInt(inputs[0]);
            a = new int[n];
            b = Integer.parseInt(inputs[1]);
            String[] input2 = br.readLine().split(" ");
            for (int j = 0; j < n; j++)
                a[j] = Integer.parseInt(input2[j]);

            Arrays.sort(a);
            count = 0;

            for (int j = 0; j < n; j++) {
                b = b - a[j];
                if (b < 0) {
                    break;
                }
                count++;
            }
            bufferedWriter.write((String.format("Case #%d :%d", i, count)));
            bufferedWriter.newLine();
        }
        br.close();
        bufferedWriter.close();
    }

}

I have passed all test cases but whenever I submit my code, got sample failed: WA in resul....I dont know where I left something

0

There are 0 answers