-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathHeroesFightMonsters.java
More file actions
65 lines (61 loc) · 1.71 KB
/
HeroesFightMonsters.java
File metadata and controls
65 lines (61 loc) · 1.71 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package company;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;
/**
* @Author: Wenhang Chen
* @Description:
* @Date: Created in 19:38 4/7/2020
* @Modified by:
*/
public class HeroesFightMonsters {
static class Monster {
int defend;
int attack;
public Monster(int defend, int attack) {
this.attack = attack;
this.defend = defend;
}
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int D = sc.nextInt();
int[][] a = new int[n][2];
for (int i = 0; i < n; i++) {
// 破防
a[i][0] = sc.nextInt();
}
for (int i = 0; i < n; i++) {
// 伤害
a[i][1] = sc.nextInt();
}
List<Monster> list = new ArrayList<>();
for (int i = 0; i < n; i++) {
list.add(new Monster(a[i][0], a[i][1]));
}
list.sort(new Comparator<Monster>() {
@Override
public int compare(Monster o1, Monster o2) {
if (o1.defend > o2.defend || o1.defend == o2.defend && o1.attack > o2.attack) {
return 1;
} else if (o1.defend == o2.defend && o1.attack == o2.attack) {
return 0;
} else {
return -1;
}
}
});
long damage = 0;
for (Monster monster : list) {
if (monster.defend <= D) {
D++;
} else {
D++;
damage += monster.attack;
}
}
System.out.println(damage);
}
}