-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDragons.java
More file actions
56 lines (47 loc) · 1.17 KB
/
Dragons.java
File metadata and controls
56 lines (47 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
51
52
53
54
55
56
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Scanner;
public class Dragons
{
public static void main( String[] args )
{
Scanner s = new Scanner( System.in );
int S = s.nextInt();
int n = s.nextInt();
int[][] dragons = new int[n][2];
boolean won = true;
ArrayList<DragonPower> listPower = new ArrayList<>();
while(n-->0)
{
listPower.add( new DragonPower(s.nextInt(), s.nextInt()) );
}
Collections.sort( listPower, (o1, o2)->o1.power-o2.power );
for( DragonPower power : listPower)
{
if(S>power.power)
{
S+=power.winPoints;
}
else
{
won = false;
break;
}
}
if(won)
System.out.println( "YES" );
else
System.out.println( "NO" );
}
}
class DragonPower
{
int power;
int winPoints;
DragonPower(int power, int winPoints)
{
this.power = power;
this.winPoints = winPoints;
}
}