Café loyalty stickers
A café gives a free coffee to every customer with at least R stickers. Customer i has s[i] stickers and may be given at most e[i] bonus stickers. The café has B bonus stickers in total. Find the largest number of customers who can get a free coffee.
Reported in: Infosys (SP / DSE · 22 Nov 2026) (memory-based)
Input
First line: N. Next N lines: s[i] and e[i]. Last line: R and B.
Output
The largest number of free coffees.
Constraints
1 ≤ N ≤ 10^5; 0 ≤ s[i], e[i] ≤ 10^9; 1 ≤ R, B ≤ 10^14.
Example 1
Input:
4
5 2
3 1
8 0
1 9
6 5
Output:
2Example 2
Input:
3
0 10
0 10
0 10
4 9
Output:
2Hint: Customers who already have R stickers cost nothing. Any other customer costs R − s[i] bonus stickers, or cannot be helped if that is more than e[i]. Help the cheapest ones first until the bonus stickers run out. Use 64-bit integers.