-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAkcija.java
More file actions
33 lines (29 loc) · 759 Bytes
/
Copy pathAkcija.java
File metadata and controls
33 lines (29 loc) · 759 Bytes
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
import java.util.*;
public class Akcija {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int[] prices = new int[n];
int index;
//add all the prices into the array
for(int i=0; i<n; i++){
index = sc.nextInt();
prices[i] = index;
}
//sort the array
Arrays.sort(prices);
int sum = 0;
int counter = 0;
for(int i = prices.length-1; i>=0; i--){
if(counter < 2){
sum+= prices[i];
counter++;
}
else{
counter = 0;
continue;
}
}
System.out.println(sum);
}
}