Skip to content

Instantly share code, notes, and snippets.

@TPAKC
Last active August 29, 2015 14:18
Show Gist options
  • Save TPAKC/a45b390e1791c20f7445 to your computer and use it in GitHub Desktop.
Save TPAKC/a45b390e1791c20f7445 to your computer and use it in GitHub Desktop.
import java.util.*;
import java.io.IOException;
public class Main {
public static void main (String[] args) throws IOException
{
Scanner in = new Scanner(System.in);
long sila = in.nextLong();
int n = in.nextInt();
String finish = "YES";
int[][] array = new int[n][2];
for (int i = 0; i <n; i++) {
array[i][0] = in.nextInt();
array[i][1] = in.nextInt();
}
for(int i =n-1 ; i > 0 ; i--){
for(int j = 0 ; j < i ; j++){
if( array[j][0] > array[j+1][0] ){
int tmp = array[j][0];
array[j][0] = array[j+1][0];
array[j+1][0] = tmp;
int tmx = array[j][1];
array[j][1] = array[j+1][1];
array[j+1][1] = tmx;
}}}
for (int i = 0; i <n; i++) {
if(array[i][0]>=sila)finish="NO";
sila+=array[i][1];
}
System.out.println(finish);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment