@@ -0,0 +1,2467 @@
+import java.io.*;%0Aimport java.math.*;%0Aimport java.security.*;%0Aimport java.text.*;%0Aimport java.util.*;%0Aimport java.util.concurrent.*;%0Aimport java.util.regex.*;%0A%0Apublic class Solution %7B%0A%0A    // Complete the luckBalance function below.%0A    static int luckBalance(int k, int%5B%5D%5B%5D contests) %7B%0A        ArrayList%3CInteger%3E imp = new ArrayList%3CInteger%3E();%0A        ArrayList%3CInteger%3E unimp = new ArrayList%3CInteger%3E();%0A        for(int i=0;i%3Ccontests.length;i++)%7B%0A            if(contests%5Bi%5D%5B1%5D==1) imp.add(contests%5Bi%5D%5B0%5D);%0A            else unimp.add(contests%5Bi%5D%5B0%5D);%0A        %7D%0A        Collections.sort(imp);%0A        Collections.sort(unimp);%0A        int total = 0;%0A        //ArraySta%0A        if(imp.size()-k%3E=0)%7B%0A            for(int i=0;i%3Cimp.size()-k;i++)%7B%0A                total-=imp.get(i);%0A                System.out.println(total);%0A                //imp.remove(i);%0A            %7D            %0A        %7D%0A        else%7B%0A            for(int i=0;i%3Cimp.size();i++)%7B%0A                total+=imp.get(i);%0A                System.out.println(total);%0A                //imp.remove(i);%0A            %7D %0A        %7D%0A%0A        if(!imp.isEmpty() && imp.size()-k%3E=0)%7B%0A            for(int i=imp.size()-k;i%3Cimp.size();i++)%7B%0A                total+=imp.get(i);%0A                System.out.println(total);%0A            %7D            %0A        %7D%0A        if(!unimp.isEmpty())%7B%0A            for(int i : unimp)%7B%0A                total+=i;%0A                System.out.println(total);%0A            %7D%0A        %7D%0A        return total;%0A    %7D%0A%0A    private static final Scanner scanner = new Scanner(System.in);%0A%0A    public static void main(String%5B%5D args) throws IOException %7B%0A        BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(System.getenv(%22OUTPUT_PATH%22)));%0A%0A        String%5B%5D nk = scanner.nextLine().split(%22 %22);%0A%0A        int n = Integer.parseInt(nk%5B0%5D);%0A%0A        int k = Integer.parseInt(nk%5B1%5D);%0A%0A        int%5B%5D%5B%5D contests = new int%5Bn%5D%5B2%5D;%0A%0A        for (int i = 0; i %3C n; i++) %7B%0A            String%5B%5D contestsRowItems = scanner.nextLine().split(%22 %22);%0A            scanner.skip(%22(%5Cr%5Cn%7C%5B%5Cn%5Cr%5Cu2028%5Cu2029%5Cu0085%5D)?%22);%0A%0A            for (int j = 0; j %3C 2; j++) %7B%0A                int contestsItem = Integer.parseInt(contestsRowItems%5Bj%5D);%0A                contests%5Bi%5D%5Bj%5D = contestsItem;%0A            %7D%0A        %7D%0A%0A        int result = luckBalance(k, contests);%0A%0A        bufferedWriter.write(String.valueOf(result));%0A        bufferedWriter.newLine();%0A%0A        bufferedWriter.close();%0A%0A        scanner.close();%0A    %7D%0A%7D%0A

add LuckBalance.java