-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLC2530.java
More file actions
50 lines (40 loc) · 1.17 KB
/
LC2530.java
File metadata and controls
50 lines (40 loc) · 1.17 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/*
* LC2530
*/
import java.util.*;
public class LC2530 {
public static long maxKelements(int[] nums, int k) {
PriorityQueue<Integer> pq = new PriorityQueue<>(Collections.reverseOrder());
int n = nums.length;
for (int i = 0; i < n; i++) {
pq.offer(nums[i]);
}
long score = 0;
while (k > 0) {
int val = pq.poll();
score += val;
pq.offer((int) Math.ceil(val / 3.0));
k--;
}
return score;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter Array Size : ");
int size = sc.nextInt();
System.out.println();
int arr[] = new int[size];
System.out.println("Enter Array Elements : ");
for (int i = 0; i < arr.length; i++) {
System.out.printf("[%d] : ", i);
arr[i] = sc.nextInt();
}
System.out.println();
System.out.print("Enter the K Value : ");
int k = sc.nextInt();
System.out.println();
long ans = maxKelements(arr, k);
System.out.println(ans);
sc.close();
}
}