CF810B.Summer sell-off

普及-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Summer holidays! Someone is going on trips, someone is visiting grandparents, but someone is trying to get a part-time job. This summer Noora decided that she wants to earn some money, and took a job in a shop as an assistant.

Shop, where Noora is working, has a plan on the following n days. For each day sales manager knows exactly, that in i-th day k__i products will be put up for sale and exactly l__i clients will come to the shop that day. Also, the manager is sure, that everyone, who comes to the shop, buys exactly one product or, if there aren't any left, leaves the shop without buying anything. Moreover, due to the short shelf-life of the products, manager established the following rule: if some part of the products left on the shelves at the end of the day, that products aren't kept on the next day and are sent to the dump.

For advertising purposes manager offered to start a sell-out in the shop. He asked Noora to choose any f days from n next for sell-outs. On each of f chosen days the number of products were put up for sale would be doubled. Thus, if on i-th day shop planned to put up for sale k__i products and Noora has chosen this day for sell-out, shelves of the shop would keep 2·k__i products. Consequently, there is an opportunity to sell two times more products on days of sell-out.

Noora's task is to choose f days to maximize total number of sold products. She asks you to help her with such a difficult problem.

暑假到了!有人去旅行,有人去探望祖父母,而有人则尝试找一份兼职工作。这个暑假,诺拉决定赚点钱,于是到一家商店当助理。

诺拉工作的这家商店制定了接下来 nn 天的销售计划。对于每一天,销售经理都确切地知道:第 ii 天将上架 kik_i 件商品,且当天恰好有 lil_i 名顾客光顾该店。此外,经理确信:每位进店的顾客都会恰好购买一件商品;若店内已无商品可售,则顾客会空手离开。而且,由于商品保质期较短,经理还制定了如下规则:若某天结束时货架上仍有剩余商品,则这些剩余商品不会保留至次日,而是直接销毁。

出于广告宣传目的,经理提议在店内开展“清仓大促”活动。他请诺拉从接下来的 nn 天中任选 ff 天作为促销日。在所选的每一天,上架的商品数量将翻倍。因此,若第 ii 天原计划上架 kik_i 件商品,而诺拉选择了这一天作为促销日,则当天货架上将摆放 2⋅ki2 \cdot k_i 件商品。这样,在促销日便有机会售出两倍数量的商品。

诺拉的任务是选择 ff 天,以使总共售出的商品数量最大化。她请你帮助她解决这一难题。

输入格式

The first line contains two integers n and f (1 ≤ n ≤ 105, 0 ≤ f ≤ n) denoting the number of days in shop's plan and the number of days that Noora has to choose for sell-out.

Each line of the following n subsequent lines contains two integers k__i, l__i (0 ≤ k__i, l__i ≤ 109) denoting the number of products on the shelves of the shop on the i-th day and the number of clients that will come to the shop on i-th day.

第一行包含两个整数 nn 和 ff(1≤n≤1051 \leq n \leq 10^5,0≤f≤n0 \leq f \leq n),分别表示商店计划中的天数以及诺拉必须选择用于促销的天数。

接下来的 nn 行中,每行包含两个整数 kik_i、lil_i(0≤ki,li≤1090 \leq k_i, l_i \leq 10^9),分别表示第 ii 天商店货架上的商品数量以及第 ii 天将到店的顾客数量。

输出格式

Print a single integer denoting the maximal number of products that shop can sell.

输出一个整数,表示商店最多能售出的产品数量。

输入输出样例

  • 输入#1

    4 2
    2 1
    3 5
    2 3
    1 5

    输出#1

    10
  • 输入#2

    4 1
    0 2
    0 3
    3 5
    0 6

    输出#2

    5

说明/提示

In the first example we can choose days with numbers 2 and 4 for sell-out. In this case new numbers of products for sale would be equal to [2, 6, 2, 2] respectively. So on the first day shop will sell 1 product, on the second — 5, on the third — 2, on the fourth — 2. In total 1 + 5 + 2 + 2 = 10 product units.

In the second example it is possible to sell 5 products, if you choose third day for sell-out.

在第一个例子中,我们可以选择第 2 天和第 4 天进行清仓销售。此时各天待售商品数量将分别变为
[2, 6, 2, 2]。
因此,商店在第 1 天将售出 1 件商品,第 2 天售出 5 件,第 3 天售出 2 件,第 4 天售出 2 件。总共售出 1 + 5 + 2 + 2 = 101 + 5 + 2 + 2 = 10 件商品。

在第二个例子中,若选择第 3 天进行清仓销售,则最多可售出 5 件商品。

输入解题思路,AI测评打分。不知道怎么写?

首页