Maximum monsters defeated
You start with E experience points. Monster i needs at least power[i] points to beat, and beating it gives you bonus[i] more points. If you fight a monster you cannot beat, you lose. You may fight the monsters in any order. What is the largest number you can defeat?
Reported in: Infosys (SP / DSE · earlier papers) (memory-based)
Input
First line: N and E. Second line: N powers. Third line: N bonuses.
Output
The largest number of monsters defeated.
Constraints
1 ≤ N ≤ 10^5; 0 ≤ E, power[i], bonus[i] ≤ 10^9.
Example 1
Input:
3 1
1 2 10
1 1 5
Output:
2Example 2
Input:
2 5
6 5
3 4
Output:
2Example 3
Input:
1 0
1
5
Output:
0Hint: Bonuses never lower your points, so fight the weakest monsters first: sort by power and stop at the first one you cannot beat. Use 64-bit integers for the points.