博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Codeforces Round #415 (Div. 2) B. Summer sell-off
阅读量:5240 次
发布时间:2019-06-14

本文共 3270 字,大约阅读时间需要 10 分钟。

http://codeforces.com/contest/810/problem/B

B. Summer sell-off
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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 ki products will be put up for sale and exactly li 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 fdays 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 ki products and Noora has chosen this day for sell-out, shelves of the shop would keep ki 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.

Input

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 ki, li (0 ≤ ki, li ≤ 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.

Output

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

Examples
input
4 2 2 1 3 5 2 3 1 5
output
10
input
4 1 0 2 0 3 3 5 0 6
output
5
Note

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.

 

 题意:每一天有k产品和l顾客,如果可以有f天的产品可以翻倍,那么最后卖出的总的销售量是多少?

 题解:定义结构体中的数据k,l,count(加倍可以增加的量)。则根据count排序,给前f天产品翻倍。然后遍历一遍,每次输出能够卖掉的产品数量。

#include
using namespace std;const int N=1e5+7;struct node{ long long k,l; long long count; }day[N];bool cmp(node a,node b) //按照翻倍后多余的量排序 { return a.count>b.count; } int main() { int n,f; cin>>n>>f; for(int i=1;i<=n;i++) { cin>>day[i].k>>day[i].l; if(day[i].k
day[i].l) ans+=day[i].l; else ans+=day[i].k; } cout<
<

 

转载于:https://www.cnblogs.com/Scalpel-cold/p/7193672.html

你可能感兴趣的文章
【Static Program Analysis - Chapter 3】Type Analysis
查看>>
第4次作业类测试代码+163+张玉洁
查看>>
Linux磁盘管理及LVM讲解
查看>>
SQL Server 2008数据类型
查看>>
Linux服务器注意事项
查看>>
vs2010 项目生成成功,发布失败
查看>>
把文件保存到 sdcard
查看>>
大数据时代下的企业管理创新
查看>>
ES6数组
查看>>
洛谷 [P2051] 中国象棋
查看>>
『题解』UVa11324 The Largest Clique
查看>>
iPhone深入浅出 iOS 之生命周期
查看>>
算法笔记_097:蓝桥杯练习 算法提高 P1001(Java)
查看>>
OpenGL3-绘制各种图元绘制
查看>>
elasticsearch 聚合查询
查看>>
安卓app测试之Monkeyrunner
查看>>
C++小点之可调用类型声明std::function
查看>>
华为项目Tree canvas画图 数据4
查看>>
Python os.getcwd() 方法
查看>>
python os.path模块
查看>>