贪心加排序
来源:互联网 发布:instagram软件下载 编辑:程序博客网 时间:2024/06/03 04:41
time limit per test
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 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 kiproducts and Noora has chosen this day for sell-out, shelves of the shop would keep 2·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.
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.
Print a single integer denoting the maximal number of products that shop can sell.
4 22 13 52 31 5
10
4 10 20 33 50 6
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.
这个题目什么意思呢,看了我三遍,TNND的,哎,还是要多做阅读理解呀。
题意:
4 代表 Noora总共要卖4天的商品,2就是Noora可以在这四天内任意选择两天,在这两天内商品的数量可以比原来翻倍。
#include <bits/stdc++.h>using namespace std;typedef long long LL;int main(){ LL n,f; LL goods[100009]; LL client[100009]; LL more[100009]; LL this_[100009]; LL other[100009]; while(cin>>n>>f) { LL sum=0; for(LL i=0;i<n;i++) { cin>>goods[i]>>client[i]; this_[i]=min(goods[i],client[i]); sum+=this_[i]; } for(LL i=0;i<n;i++)//翻倍后 goods[i]*=2; for(LL i=0;i<n;i++) { other[i]=min(goods[i],client[i]); } for(LL i=0;i<n;i++) { more[i]=other[i]-this_[i]; } sort(more,more+n,greater<LL>());//greater<LL>() 就是从大到小排列 ,当然你自己也可以定义一个cmp ,我比较懒,hh for(LL i=0;i<f;i++) sum+=more[i]; cout<<sum<<endl; } return 0;}
// 还有不懂的可以私聊哦 QQ1305703713
- 贪心加排序
- codeforces 779C 排序加贪心
- NYOJ 236心急的C小加(排序贪心)
- NYOJ236. 心急的C小加(排序+贪心)
- mysterious 二分加贪心
- HDU2037------贪心加冒泡
- poj1018 枚举加贪心
- PIE 二分加贪心
- 贪心加优先队列
- hdu 5802 搜索加贪心
- uva11134贪心加优先队列
- Kindergarten Election----枚举加贪心
- 数据汇总加排序
- 数据汇总加排序
- 数据汇总加排序
- 数据汇总加排序
- 数据汇总加排序
- 数据汇总加排序
- linux rpm安装mysql
- Nginx学习——Nginx基本配置
- 在ubuntu上安装,使用MQTT Mosquitto
- POI中文API文档
- Java字符串小结
- 贪心加排序
- 565. Array Nesting(dfs 血的教训)
- 作为Scala语法糖的设计模式
- 汇编逆向《干货收集》
- Java 对象的初始化过程
- JAVA开发中POI和JXL区分
- 【51Nod】1347 旋转字符串
- SSH连接阿里云错误:Connection reset by peer解决
- 网络流之最大流模板