1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| public class 야근지수 { public static void main(String[] args) { solution(3, new int[]{1,1}); } static long solution(int n, int[] works) { long answer = 0; PriorityQueue<Integer> pq = new PriorityQueue(Collections.reverseOrder()); for (int work : works) { pq.add(work); } int cnt = 0; while(!pq.isEmpty()){ if(cnt == n){ break; } pq.add(pq.poll()-1); cnt++; } for (Integer value : pq) { if(value < 0){ answer = 0; break; } answer += Math.pow(value, 2); } System.out.println(answer); return answer; } }
|