Codeforces Round #415 B Summer sell-off

RK3588上使用PCIE接口的国产千兆网卡YT6801 YT6801是裕太微电子开发的一款国产千兆PCIE以太网控制器芯片,可作为RK3588的PCIE外扩网口使用。 阅读详情

Summer sell-off
time limit per test1 second
memory limit per test256 megabytes

Description
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 ki products 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.

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.

题目大意:这题大概就是在n组库存与销售量关系中,找出f组,使其库存翻倍从而提高销售额,我们的目的就是找出利益最大化的f组。
看上去挺水的,我一开始直接开三个数组想暴力排序+查找,果不其然,好像是第12组数据就WA了(/”≡ _ ≡)/~┴┴
唉,之后就老老实实结构体数组排序呗,顺带写了个cmp,快速sort一下就好了,感觉写的比暴力还要快???

#include<bits/stdc++.h>
using namespace std;
int n,m;
typedef long long ll;
struct edge
{
    ll a,b,c;
}d[100005];
 bool cmp(edge A,edge B)
{
    return A.c<B.c;
}
int mak[100005];
int main()
{
    memset(mak,0,sizeof(mak));
    scanf("%d%d",&n,&m);
    for(int i=0;i<n;i++)
    {
        scanf("%lld%lld",&d[i].a,&d[i].b);
        long long int num=d[i].a*2;
        if(d[i].a<=d[i].b)//只有这种情况能提高销售额
        {
            if(num>=d[i].b)
                d[i].c=d[i].b-d[i].a;
            else if(num<=d[i].b)
                d[i].c=num-d[i].a;
            //mak[i]=1;
            //printf("%d\n",i);
        }
    }
    sort(d,d+n,cmp);
    long long int sum=0;
    for(int i=n-1;i>=0;i--)
    {
        if(i>=n-m)
        {
            if(d[i].a*2>=d[i].b)
                sum+=d[i].b;
            else
                sum+=d[i].a*2;
        }
        else
            sum+=min(d[i].a,d[i].b);
    }
    printf("%lld\n",sum);
}
ubuntu系统禁止/开启内核自动更新 内核自动更新会导致驱动和内核版本不对应,导致驱动无法使用,所以需要禁止自动更新内核。本文介绍ubuntu系统禁止/开启内核更新的方法。 阅读详情

相关推荐

折叠式共源共栅运放设计实战:Cadence Virtuoso完整流程

在模拟IC设计中,运放是信号链的核心模块,而共源共栅结构凭借高增益、高输出阻抗的特性,成为高性能放大器的经典选择。其中,折叠式共源共栅运放通过电流折叠技术,在不牺牲增益的前提下显著改善输出摆幅与输入共模范围,尤其适合1.8V低压工艺下的高动态范围应用。本文从共源共栅放大器的基本原理出发,解析其技术价值与典型应用场景,并基于0.18μm工艺,系统展示如何利用Cadence Virtuoso完成从电路结构分析、管子尺寸推导到原理图绘制、仿真调试的完整设计闭环。内容涵盖增益、带宽、相位裕度等关键指标的优化方法,以

weixin_34277853的博客 383

【CodeForces】810B. Summer sell-off 题解

题目来自于:CodeForces - 810B 题目解读:这里题目说的是如何求得最大商品销售量。首先,每天有k件商品,有l个客人,每日的商品必须当天卖出,每个客人只且只能买一件商品,但是在任选限定f天里面,商品的数量可以翻倍。现在让你求最大销售量。 算法设计: 1.求翻倍后每日能多卖的商品就好,最后取排序的前f位。 2.这题的数据量比较庞大,数组要开够。可以用快排,sort,qsort内置排序...

Drmon.的博客 441

Aras Innovator生命周期图实战:从配置到权限管理的全流程解析

本文详细解析了Aras Innovator生命周期图的全流程配置与权限管理,从基础概念到实战应用,涵盖状态设置、路径配置、权限控制等核心功能。通过实际案例和代码示例,帮助用户掌握如何高效管理数据生命周期,提升业务流程的规范性和效率。

ee345的博客 183

cf Summer sell-off

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 trip

mayuqing98的博客 410

项目管理-(补充)七种基本质量工具

七种基本质量工具,用于PDCA循环的架构内 解决与质量相关的问题,分为老七工具和新七工具。 1)老七种:刘英只点劣质茶(流程图、因果图、直方图、散点图、帕累托图、控制图、核查表)2)新七种:锯树联亲测动优(矩阵图、树形图、关联图、亲和图、过程决策程序图、活动网络图、优先矩阵)

weixin_42081167的博客 4615

[逆向实战] 淘宝x5sec滑条验证码slidedata参数逆向与自动化过码方案

本文详细解析了淘宝x5sec滑条验证码的核心参数slidedata的生成机制与逆向过程,提供了Python自动化过码方案。通过分析滑动轨迹加密流程、还原AES加密算法,并设计人类行为模拟轨迹,帮助开发者有效绕过淘宝滑块验证,适用于爬虫开发与自动化测试场景。

weixin_30851867的博客 748

CodeForces 810B Summer sell-off 【贪心】【排序】

题目链接:Codeforces Round #415 (Div. 2) BDescription: 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

咸鱼の小窝 1125

zedboard(5)spi轮询和中断

一个SPI可以有几个从设备 在程序中使用 s32 XSpiPs_SetSlaveSelect(XSpiPs *InstancePtr, u8 SlaveSel) 选择。其实就是吧对应设备的ss拉低。 备注:只选一个ss,可以不用指定。(感觉,还没测试) 这是xspips.c中定义的函数,发送和接收有 XSpiPs_Transfer 和 XSpiPs_PolledTransfer 两个函数,分别采用中断和轮询模式。    一、轮询模式 米联客参考代码,SpiPs_Init中部分和官方例程流程一样,Spi

Kiss丶小坏 5899

CodeForces #415(div2) Summer sell-off(贪心)

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 trip

Timeclimber 741

附录B:Standard Delay Format(SDF)(上)

本附录将介绍标准延迟标注格式,并说明了如何在仿真中执行反标。 延迟格式描述了设计网表的单元延迟和互连走线延迟,无论设计是用两种主要硬件描述语言(VHDL或Verilog HDL)中的哪一种所描述的。 本章还会介绍仿真的反标(backannotation),STA的反标其实是一个简单直接的过程,其中DUA中的时序弧将由SDF所指定的延迟进行标注。

To the beyond and infinity! 5425

数控弯管机xyz转换ybc的算法_花了一年时间开发的三维弯管机交互式转档软件(三维管子模型UG,SOLIDWORK,PRO/E文件转成YBC)...

在弯管机加工中,由管子模型生成可直接进行弯管加工的YBC数据可以大大提高弯管编程过程.传统的做法是先用dxf数据文件(用autocad绘制管子的轴心线数据)转出XYZ数据,然后由XYZ数据转成YBC数据,而且大部分厂家对文件版本以及软件做管方式都有不少限制,这大大花费了用户的时间跟精力.随着企业的信息化管理以及不断的技术升级,传统用autocad线条模式来描述管子的方式正在被用户用PRO/E,UG...

weixin_29065959的博客 1980

Codeforces Round #415 (Div. 2)- B. Summer sell-off——算法笔记

题目链接:http://codeforces.com/problemset/problem/810/B 题目描述: Summer holidays! Someone is going on trips, someone is visiting grandparents, but someone is trying to get a part-time job. This summer Noora...

学而不思则忘 409

国产信创服务器软硬件兼容情况1 --- ARM架构

信创,即信息技术应用创新产业,它是数据安全、网络安全的基础,也是新基建的重要组成部分...

一只猿的自我修养 4756

Codeforces Round #415 (Div. 2)B. Summer sell-off (水题)

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

HHH_go_的博客 922

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

InTheHand.Net.Personal+BlueTooth4,蓝牙开发

项目中有蓝牙开发的必备dll,现在网上相关的文档博客不少,有的说的多有的说少,但是却很少有这两个dll,分享一下。

Codeforces Round #415 (Div. 2) B. Summer sell-off

贪心。 用结构体保存的struct node { ll k,l,val; };本来是在输入的时候令val=2*k,然后按照val从大到小排序,按条件选取,在test15那里错了,后来就想啊想,令val=l-k或者val=2*k-k,val就表示商品翻倍那天额外多赚的,然后在按照val从从大到小排序,就过了,之前那种排序方式排在前面的并不一定是额外赚的多的#include <iostream

梦幻的蔷薇色 400

Outlook Express 6 (OE6) for Win7/Win8/Win10

英文版 Outlook Express6.0, 兼容Win7/Win10/WinXP,解压就可用。

Codeforces Round #415 (Div. 2) B. Summer sell-off

B. Summer sell-off 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 mone

lwlldd的专栏 472

Codeforces Round #415 (Div. 2) B. Summer sell-off

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...

weixin_30838921的博客 101

Codeforces Round #415 (Div. 2) B. Summer sell-off

B. Summer sell-off time limit per test 1 second memory limit per test 256 megabytes Summer holidays! Someone is going on trips, someone is visiting grandparents, but someone ...

weixin_30262255的博客 96

平常水题 — Codeforces Round #415 (Div. 2) B. Summer sell-off (贪心 + 错误总结)

B. Summer sell-off time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output Summer holidays! Someone is going on trips, someone is visiting grandpa

dreams___的博客 399

Codeforces 810B Summer sell-off 题解

Codeforces 810B题解

DarkoDu的博客 610

CF - 810B. Summer sell-off - 贪心+排序

1.题目描述: 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

终有绿洲摇曳在沙漠 978

codeforces 810 B. Summer sell-off【贪心】

B. Summer sell-off time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output Summer holidays! Someone is going on trips, someone is visiting grandpa

nobleman 528

Codeforces Round #469 (Div. 2) D. A Leapfrog in the Array (思维)

题目大意:最开始n个数字中的数字i在位置2*i-1,之后从右向左依次用数字将该列填充。最后q个query问你pos为Xi该填上什么数字。 解析:首先n范围1e18,直接模拟肯定不行,但肯定有什么规律在里面,我们自己写写看n=6的时候,1~6位置分别为1 4 2 6 3 5,n=3的时候1~3位置分别为1 3 2,这里我们可以明显的发现,当Xi&amp;1时,该位置最后的数字就是Xi/2+1。...

喵喵喵? 1257

Codeforces Round #499 (Div. 1) C. Border || Codeforces Round #499 (Div. 2) E.Border(数论/贝祖定理)

                Codeforces Round #499 (Div. 1) C. Border                 Codeforces Round #499 (Div. 2) E. Border                                          (数论/贝祖定理)   题意:给你n个数字(十进制),每个数字都可以使用无限次...

喵喵喵? 992

ICM Technex 2017 and Codeforces Round #400 (Div. 1 + Div. 2, combined) C. Molly's Chemicals

Molly’s Chemicals time limit per test 2.5 seconds memory limit per test 512 megabytes Description Molly Hooper has n different kinds of chemicals arranged in a line. Each of the chemicals has

喵喵喵? 903

Codeforces Round #476 (Div. 2) [Thanks, Telegram!] C. Greedy Arkady(brute force/math)

C. Greedy Arkady 传送门 这题的关键就是算出自己一共receive了多少次,我们可以很容易的便推出这么一个式子—&gt;(nx+k−1)k(nx+k−1)k\frac{(\frac{n}{x}+k-1)}{k} 之后嘛暴力二分一下就好啦 #include&lt;cstdio&gt; #include&lt;iomanip&gt; #include&lt;cstring&...

喵喵喵? 860

Codeforces Round #480 (Div. 2) D. Perfect Groups(数论/xjblg)

D. Perfect Groups 传送门 今天vp了一下昨天的这场比赛,结束后看着rank,还好没打, 这场完全就是题意场啊,做题10mins,读题1h…….. 这个D题题意是真的有点魔性: 首先第一段描述的ansansans是指给你一个array,使得你能将他分成numnumnum个集合,使得集合中任意两个书之积为完全平方数,且numnumnum是满足条件的最小集合数。 第二三...

喵喵喵? 789
上一篇: Codeforces Round #415 A Straight <<A>>
下一篇: Codeforces Round #415 C. Do you want a date?
Murphyc
博客等级 码龄10年 13粉丝 86原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值