-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbank.java
55 lines (38 loc) · 939 Bytes
/
bank.java
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
51
52
53
54
55
import java.util.ArrayList;
import java.util.Scanner;
class Person{
int money;
int time;
public Person(int a, int b){
money = a;
time = b;
}
}
public class bank {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
ArrayList<Person> pop = new ArrayList<Person>();
int people = scan.nextInt();
int timeLeft = scan.nextInt();
for(int i=0; i < people; i++)
pop.add(new Person(scan.nextInt(), scan.nextInt()));
int money = 0;
for(int i=timeLeft; i >=0; i--){
int curr = -1;
int ind = -1;
for (int j = 0; j < pop.size(); j++)
if (pop.get(j).time >= i)
if (pop.get(j).money > curr)
{
curr = pop.get(j).money;
ind = j;
}
if(ind != -1){
money += pop.get(ind).money;
pop.remove(ind);
}
}
System.out.println(money);
scan.close();
}
}