A couple of feedback:

   1. Most of the time you shouldn't need to implement sorting yourself. 
   You should take advantage of the sorting library that comes with your 
   languages/platform for free
   In this case, you should sort the array using Arrays.sort() in Java
   2. In contadorCasas(), you take v[0] before the array is sorted. This is 
   not correct and you should take v[0] after sorting
   3. Your sorting is a bubble sort and the sorting order is reversed.


Please find a passing solution below or at https://ideone.com/TveUjS

*import java.util.*;*
*import java.lang.*;*
*import java.io.*;*

*class Solution {*
*    public static void main(String[] args) {*
*        int t, n, b, value, n_casas;*
*        Scanner S = new Scanner(System.in);*
*        t = S.nextInt();*
*        int cases[] = new int[t];*
*        for (int i = 0; i < t; i++) {*
*            n = S.nextInt();*
*            b = S.nextInt();*
*            int a[] = new int[n];*
*            for (int j = 0; j < n; j++) {*
*                value = S.nextInt();*
*                a[j] = value;*
*            }*
*            n_casas = contadorCasas(a, b);*
*            cases[i] = n_casas;*
*        }*
*        for (int i = 0; i < t; i++) {*
*            System.out.println("Case #" + (i + 1) + ": " + cases[i]);*
*        }*
*    }*


*    static int contadorCasas(int v[], int b) {*
*        Arrays.sort(v);*
*        int aux = v[0];*
*        int counter = 0;*

*        if (aux <= b) {*
*            counter++;*
*            for (int i = 1; i < v.length; i++) {*
*                if (aux + v[i] <= b) {*
*                    aux += v[i];*
*                    counter++;*
*                }*
*            }*
*        }*
*        return counter;*
*    }*
*}*

-- 
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 google-code+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-code/0a155acb-5f08-45af-b110-c9fa914f4187%40googlegroups.com.

Reply via email to