CSES - Datatähti 2017 alku - Results
Submission details
Task:Kolikot
Sender:planckcons
Submission time:2016-10-08 13:10:33 +0300
Language:Java
Status:COMPILE ERROR

Compiler report

input/Kolikot.java:18: error: cannot find symbol
            clear.add(arr[i]);
            ^
  symbol:   variable clear
  location: class Kolikot
input/Kolikot.java:20: error: cannot find symbol
        clear.sort(null);
        ^
  symbol:   variable clear
  location: class Kolikot
input/Kolikot.java:22: error: cannot find symbol
        while(k == (int)(clear.get(0)))
                         ^
  symbol:   variable clear
  location: class Kolikot
input/Kolikot.java:25: error: cannot find symbol
            clear.remove(0);
            ^
  symbol:   variable clear
  location: class Kolikot
input/Kolikot.java:33: error: cannot find symbol
            while(k == (int)(clear.get(0)))
                             ^
  symbol:   variable clear
  location: class Kolikot
input/Kolikot.java:36: error: cannot find symbol
                clear.remove(0);
                ^
  symbol:   variable clear
  location: class Kolikot
input/Kolikot.java:37: error: cannot find symbol
                if(cle...

Code

import java.util.Scanner;

public class Kolikot {
    
    public static void main(String[] args) 
    {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int[] arr = new int[n];
	int k = 1;
	int max = 0;        

        for(int i = 0; i < n; i++)
        {
            arr[i] = scan.nextInt();
            if(arr[i] > max)
                max = arr[i];
            clear.add(arr[i]);
        }
        clear.sort(null);
        
        while(k == (int)(clear.get(0)))
        {
            k++;
            clear.remove(0);
        }
        
        while(isSubsetSum1(arr, n, k))
        {
            k++;
            if(k > max)
                continue;
            while(k == (int)(clear.get(0)))
            {
                k++;
                clear.remove(0);
                if(clear.isEmpty())
                    break;
            }
        }
        System.out.println(k);
    }
    
    static boolean isSubsetSum1(int arr[], int n, int sum) {

        boolean[][] subset = new boolean[sum + 1][n + 1];
        int i, j;

        for (i = 0; i <= n; i++) {
            subset[0][i] = true;
        }

        for (i = 1; i <= sum; i++) {
            subset[i][0] = false;
        }

        for (i = 1; i <= sum; i++) {
            for (j = 1; j <= n; j++) {
                subset[i][j] = subset[i][j - 1];

                if (i >= arr[j - 1]) {
                    subset[i][j] = subset[i][j] || subset[i - arr[j - 1]][j - 1];
                }
            }
        }
        return subset[sum][n];
    } 
}