Mobile Ad Bidding
InterviewTime limit2sMemory limit1024 MB
Find the smallest nonnegative integer X so that adding X to every bid A_i makes A_i + X at least B_i in at least K slots.
Problem
Rights to ad slots in the mobile ad market are decided through real-time auctions. In each auction, companies that want to place an ad submit bids, and the company with the highest bid wins the ad rights for that slot. The process requires analyzing and bidding on countless ad slots worldwide in real time.
MOLOCO runs the MOLOCO Cloud DSP service, which helps clients reach the mobile ad market. The service uses machine learning to process several million bid requests per second. MOLOCO bids on behalf of its clients and helps them buy ad slots at the best price.
You are improving the bidding logic of the Cloud DSP service at MOLOCO. Your goal is to analyze the bidding data for past important ad slots and improve how the bid price is determined.
For each ad slot , you are given MOLOCO's bid and the highest bid among all other bids, excluding MOLOCO's. Suppose MOLOCO raises its bid in every slot by , so its bid becomes instead of . Find the smallest nonnegative integer such that MOLOCO wins at least slots. If MOLOCO's bid ties the highest other bid in a slot, MOLOCO wins that slot.
Input
The first line contains and , separated by a space. Each of the next lines contains and for ad slot , separated by a space.
Output
Print the smallest nonnegative integer such that MOLOCO wins at least slots.
Constraints
- All given numbers are integers.
- for