@@ -0,0 +1,1835 @@
+// http://codeforces.com/problemset/problem/230/A%0A%0Aimport java.util.Scanner;%0Aimport java.util.Set;%0Aimport java.util.TreeSet;%0A%0Apublic class Solution %7B%0A%09%0A%09static class Dragon implements Comparable%3CDragon%3E %7B%0A%09%09private int strength;%0A%09%09private int defeatBonus;%0A%09%09%0A%09%09public Dragon(int strength, int defeatBonus) %7B%0A%09%09%09this.strength = strength;%0A%09%09%09this.defeatBonus = defeatBonus;%0A%09%09%7D%0A%0A%09%09public int getStrength() %7B%0A%09%09%09return strength;%0A%09%09%7D%0A%09%09public int getDefeatBonus() %7B%0A%09%09%09return defeatBonus;%0A%09%09%7D%0A%0A%09%09@Override%0A%09%09public int compareTo(Dragon otherDragon) %7B%0A%09%09%09int thisDragonStrength = this.getStrength();%0A%09%09%09int otherDragonStrength = otherDragon.getStrength();%0A%09%09%09%0A%09%09%09if (thisDragonStrength %3E otherDragonStrength) %7B%0A%09%09%09%09return 1; // thisDragon is greater%0A%09%09%09%7D%0A%09%09%09else if (thisDragonStrength %3C otherDragonStrength) %7B%0A%09%09%09%09return -1; // otherDragon is greater%0A%09%09%09%7D%0A%09%09%09else %7B%0A%09%09%09%09int thisDragonDefeatBonus = this.getDefeatBonus();%0A%09%09%09%09int otherDragonDefeatBonus = otherDragon.getDefeatBonus();%0A%09%09%09%09if (thisDragonDefeatBonus %3E otherDragonDefeatBonus) %7B%0A%09%09%09%09%09return 1;%0A%09%09%09%09%7D%0A%09%09%09%09else %7B%0A%09%09%09%09%09return -1;%0A%09%09%09%09%7D%0A%09%09%09%7D%0A%09%09%7D%09%0A%09%7D%0A%09%0A%09public static void main(String%5B%5D args) %7B%0A%09%09Scanner read = new Scanner(System.in);%0A%09%09%0A%09%09int s = read.nextInt();%0A%09%09int n = read.nextInt();%0A%09%09%0A%09%09Set%3CDragon%3E dragons = new TreeSet%3CDragon%3E();%0A%09%09%0A%09%09for (int i = 0; i %3C n; ++i) %7B%0A%09%09%09int x = read.nextInt(); // dragon's strength%0A%09%09%09int y = read.nextInt(); // bonus for defeating dragon%0A%09%09%09dragons.add(new Dragon(x, y));%0A%09%09%7D%0A%09%09%0A%09%09boolean canMoveToNextLevel = true;%0A%09%09for (Dragon dragon : dragons) %7B%0A%09%09%09if (s %3E dragon.getStrength()) %7B%0A%09%09%09%09s += dragon.getDefeatBonus();%0A%09%09%09%7D%0A%09%09%09else %7B%0A%09%09%09%09canMoveToNextLevel = false;%0A%09%09%09%09break;%0A%09%09%09%7D%0A%09%09%7D%0A%09%09%0A%09%09if (canMoveToNextLevel) %7B%0A%09%09%09System.out.println(%22YES%22);%0A%09%09%7D%0A%09%09else %7B%0A%09%09%09System.out.println(%22NO%22);%0A%09%09%7D%0A%09%09%0A%09%09// Close scanner%0A%09%09read.close();%0A%09%7D%0A%09%0A%7D%0A

Create Dragons.java