-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDay9_230A.java
39 lines (38 loc) · 1.06 KB
/
Day9_230A.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
import java.util.Scanner;
public class Day9_230A {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int s = sc.nextInt();
int n = sc.nextInt();
int a[] = new int[n];
int b[] = new int[n];
for (int i = 0; i < n; i++) {
a[i] = sc.nextInt();
b[i] = sc.nextInt();
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (a[i] < a[j]) {
int temp = a[i];
a[i] = a[j];
a[j] = temp;
int temp2 = b[i];
b[i] = b[j];
b[j] = temp2;
}
}
}
boolean bool = false;
for (int i = 0; i < n; i++) {
if (a[i] >= s) {
bool = true;
System.out.println("NO");
return;
} else {
s = s + b[i];
}
}
if (bool == false)
System.out.println("YES");
}
}