Another Contest 5 Problem 3 - Cutting Cheese Costs

View as PDF

Submit solution

Points: 5 (partial)
Time limit: 1.0s
Memory limit: 256M

Problem type

Tudor is buying N blocks of cheese. Each block of cheese has a regular price and a discounted price.

Tudor has K coupons that allow him to buy a block of cheese for the discounted price instead of the regular price. Each coupon can be used for exactly one block of cheese.

Given that Tudor wants to buy all N blocks of cheese, compute the minimum amount of money he must spend.


1 \le N \le 10^5

0 \le K \le N

1 \le d_i \le p_i \le 10^9

Input Specification

The first line contains two space separated integers, N and K.

The next N lines each contain two space separated integers, p_i and d_i representing the regular price and discounted price of block i, respectively.

Output Specification

Output the minimum amount of money Tudor must spend.

Sample Input

2 1
100 0
10 10

Sample Output



  • 1
    tappbros  commented on July 24, 2020, 4:59 p.m. edited

    This has nothing to do with cutting cheese. What. I mean, I know it's a block of cheese which you can cut, but, like...

    • 7
      Kirito  commented on July 24, 2020, 7:00 p.m.

      It is not the cheese that is being cut, but the price of said cheese.

      • 1
        notpeachay420  commented on Oct. 30, 2020, 1:11 p.m.

        ohhhh that makes more sense

  • 1
    Pleedoh  commented on Oct. 20, 2019, 10:19 p.m. edited

    Can anyone help me with WA (Presentation Error, check your whitespace)?

    I literally just output the answer, there is no whitespace...

    • 7
      Tzak  commented on Oct. 21, 2019, 12:27 a.m.

      You should place a \n character at the end of your output.