Codeforces Round #415 (Div. 2)B. Summer sell-off (水题)
来源:互联网 发布:解压缩软件破解版 编辑:程序博客网 时间:2024/06/17 03:37
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 followingn days. For each day sales manager knows exactly, that ini-th day ki products will be put up for sale and exactlyli 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 anyf days from n next for sell-outs. On each off chosen days the number of products were put up for sale would be doubled. Thus, if oni-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 keep2·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 thei-th day and the number of clients that will come to the shop oni-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 numbers2 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 sell1 product, on the second — 5, on the third —2, on the fourth — 2. In total1 + 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.
题意:有n天每天有存货量和需求量,其中有 f 天可以让存货量加倍,问最大售出量为多少。
分析:一开始以为是dp,其实只需要把需求量少于存货量的直接加起来,然后再将剩下的按可增加的销量排序。
就可以得到答案。
AC代码:
#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;struct tree{long long h,w,c; //存货,需求,可增加贩卖量 }p[200000];bool com(tree a,tree b){return a.c>b.c;}int main(){long long ans=0;int n,k,t=0;scanf("%d%d",&n,&k);for(int i=0;i<n;i++){long long a,b;scanf("%lld%lld",&a,&b);if(a>=b)ans+=b;else{p[t].h=a;p[t].w=b;if(b>=2*a)p[t++].c=a;elsep[t++].c=b-a;}}sort(p,p+t,com);for(int i=0,j=0;i<t;i++,j++){if(j<k)ans+=p[i].h+p[i].c;elseans+=p[i].h;}printf("%lld\n",ans);}
- Codeforces Round #415 (Div. 2) B. Summer sell-off
- Codeforces Round #415 (Div. 2) B. Summer sell-off
- Codeforces Round #415 (Div. 2)B. Summer sell-off (水题)
- Codeforces Round #415 B Summer sell-off
- 平常水题 — Codeforces Round #415 (Div. 2) B. Summer sell-off (贪心 + 错误总结)
- Codeforces 810B Summer sell-off 题解
- 【Codeforces 808 B. Summer sell-off】
- Summer sell-off (Codeforces-810B)
- CodeForces #415(div2) Summer sell-off(贪心)
- CodeForces 810B Summer sell-off 【贪心】【排序】
- CodeFroces 810B Summer sell-off
- CodeForces 810B——Summer sell-off ——贪心
- Codeforces Round #352 (Div. 2)-Summer Camp(模拟)
- cf Summer sell-off
- 水题-Codeforces Round #369 Div.2-B
- Codeforces Round #256 (Div. 2)(B)
- Codeforces Round #350 (Div. 2)(B)
- Codeforces Round #379 (Div. 2)B
- 打印weka的Instances对象里的属性
- LPC2294 ARM7 ADS1.2 AXD startup.s 取数据中止 DataAbort B DataAbort
- 1135: 盐水的故事
- 状态图与活动图傻傻分不清
- 模拟java 数据处理
- Codeforces Round #415 (Div. 2)B. Summer sell-off (水题)
- C语言 多级指针 解引用
- HTTP协议详解(真的很经典)
- SSH电力项目九--运行监控首页显示
- 如何是使用XMLHttpRequest对象实现与服务器之间的通信
- 关于用res中values中styles.xml文件写出沉浸式状态栏
- 学习淘淘商城第七十五课(nginx配置反向代理)
- semop SEM_UNDO标识
- OPA690对称电阻设置