You are viewing a single comment's thread. Return to all comments →
Java:
public static int luckBalance(int k, List<List<Integer>> contests) { int balance = 0; Collections.sort(contests, new Comparator<List<Integer>>() { @Override public int compare(List<Integer> o1, List<Integer> o2) { return o1.get(0).compareTo(o2.get(0)); } }); int n = contests.size(); for (int i = n - 1; i >= 0; i--) { int current = contests.get(i).get(0); if (contests.get(i).get(1) == 1) { if (k > 0) { balance += current; k--; } else { balance -= current; } } else { balance += current; } } return balance; }
Seems like cookies are disabled on this browser, please enable them to open this website
Luck Balance
You are viewing a single comment's thread. Return to all comments →
Java: