Online Shopping


Submit solution


Points: 1
Time limit: 2.0s
Memory limit: 256M

Author:
Problem type
Allowed languages
C, C++, Java, Python

Ray recently moved to a new city, and he's looking for some new furniture on Taobao to fill out his apartment. Ray is a thrifty shopper, so he found many items that are on sale, and he wants to maximise the amount of money saved. Ironically, Ray has virtually unlimited money to spend (as he works at the prestigious Sphinx Trading), but he can only fit a certain amount of items in his space.

Given a list of items, their original and discounted prices, and the max amount of items Ray can buy, what is the maximum amount of money he can save (i.e. the difference between the total listed price of all the items he buys, and the discounted price)? He can only buy one of each item.

Input

The first line contains an integer n\ (1 \leq n \leq 10^4), the number of items Ray found on sale on Taobao, and an integer k\ (1 \leq k \leq n), the maximum amount of items Ray can fit in his apartment.

The next n lines each contain 2 integers separated by a space. The first integer is a_i\ (1 \leq a_i \leq 10^5), the original price of the item. The second integer is b_i\ (1 \leq b_i \leq a_i), the discounted price.

Output

What is the maximum amount Ray can save by buying sale items, while not buying more than k items? The amount saved is equal to the original price minus the discounted price.

Example

Input 1
5 3
10 2
300 289
89 78
50 49
100 80
Output 2
42
  • Buying the item on sale for 289 from 300 saves 11.
  • The item on sale from 89 to 78 also saves 11.
  • Finally, the item on sale for 80 from 100 saves 20.

As such, 11+11+20=42

Input 2
4 2
100 95
8 2
77 67
38 30
Output 2
18

We buy the final two items.


Comments

There are no comments at the moment.