#K40047. Maximize Total Donation
Maximize Total Donation
Maximize Total Donation
You are given n items, where each item is characterized by two integers: the starting bid \(b_i\) and the premium factor \(p_i\). Boboniu can accept at most \(k\) bids. When he accepts a bid, he obtains a donation equal to its premium factor.
Your task is to compute the maximum total donation Boboniu can receive by selecting up to \(k\) items with the highest premium factors.
Note: The starting bid \(b_i\) is provided with each item but does not affect the donation amount.
inputFormat
The first line contains two integers \(n\) and \(k\) (\(1 \leq k \leq n \leq 10^5\)), representing the number of items and the maximum number of accepted bids respectively.
Each of the following \(n\) lines contains two integers \(b_i\) and \(p_i\) (\(0 \leq b_i, p_i \leq 10^9\)), where \(b_i\) is the starting bid and \(p_i\) is the premium factor.
outputFormat
Output a single integer representing the maximum total donation Boboniu can collect.
## sample5 3
10 5
20 10
30 15
40 20
50 25
60