-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathbank.java
More file actions
40 lines (28 loc) · 702 Bytes
/
Copy pathbank.java
File metadata and controls
40 lines (28 loc) · 702 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
34
35
36
37
38
39
40
import java.util.*;
public class bank {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int people = scan.nextInt();
int time = scan.nextInt();
ArrayList<Integer>[] bank = new ArrayList[time];
for (int i = 0; i < bank.length; i++)
bank[i] = new ArrayList<>();
while (people --> 0)
{
int money = scan.nextInt();
int leave = scan.nextInt();
bank[leave].add(money);
}
int total = 0;
ArrayList<Integer> choices = new ArrayList<Integer>();
for (int i = time - 1; i >= 0; i--)
{
choices.addAll(bank[i]);
Collections.sort(choices);
if (!choices.isEmpty())
total += choices.remove(choices.size() - 1);
}
System.out.println(total);
scan.close();
}
}