Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.util.*;
- public class Problem {
- public static void main(String[] args){
- Scanner sc = new Scanner(System.in);
- int n = sc.nextInt();
- int[] power = new int[n];
- for(int i=0; i < n; i++){
- power[i] = sc.nextInt();
- }
- int result = findPower(power, n);
- System.out.println(result);
- }
- public static int findPower(int[] power, int n) {
- PriorityQueue<Integer> maxHeap = new PriorityQueue<>(Collections.reverseOrder());
- for(int a : power)
- maxHeap.add(a);
- while (maxHeap.size() > 1){
- int a = maxHeap.poll();
- int b = maxHeap.poll();
- if(a == b)
- maxHeap.add(a);
- else
- maxHeap.add((a+b)/4);
- }
- return maxHeap.poll();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement