CSES - Aalto Competitive Programming 2024 - wk1 - Wed - Results
Submission details
Task:Apple Division
Sender:aalto2024a_007
Submission time:2024-09-04 17:29:41 +0300
Language:Java
Status:COMPILE ERROR

Compiler report

input/testing.java:32: error: cannot find symbol
            System.out.println(num.get(size())-(a1-num.get(size()))); 
                                       ^
  symbol:   method size()
  location: class testing
input/testing.java:32: error: cannot find symbol
            System.out.println(num.get(size())-(a1-num.get(size()))); 
                                                           ^
  symbol:   method size()
  location: class testing
2 errors

Code

import java.util.*;
import java.lang.Math;
public class testing{

    public static void main( String args[]){
        Scanner x = new Scanner(System.in);
        String a = x.nextLine();
        String b = x.nextLine();
        String[] arrS = b.split(" ");
        ArrayList<Integer> num = new ArrayList<Integer>();
        for(String h : arrS){
        //    System.out.println(Integer.parseInt(h));
            num.add(Integer.parseInt(h));
        }
        Collections.sort(num);
        //for(int i : num){
        //    System.out.println(i);
        //}
        int sum = 0;
        for(int g: num){
            sum += g;
        }
        int v = sum/2;
        int d = num.get(num.size());
        int o = num.get(num.size());
        int x1,x2;
        if(num.get(num.size()) >= v){
            int a1 = 0;
            for(int g : num){
                a1+=g;
            }
            System.out.println(num.get(size())-(a1-num.get(size()))); 
        }
        else{
            for(x1 = 0; x1<num.size(); x1++ ){
                if(Math.abs(d+num.get(x1)-(v))< Math.abs(d)){
                    d = d+num.get(x1)-(v);
                }
            }
            System.out.println(sum-d-(d));
        }
}
}