[ABC246C] Coupon
Problem Statement
There are $N$ items in a shop. For each $i = 1, 2, \ldots, N$, the price of the $i$-th item is $A_i$ yen (the currency of Japan).
Takahashi has $K$ coupons.
Each coupon can be used on one item. You can use any number of coupons, possibly zero, on the same item. Using $k$ coupons on an item with a price of $a$ yen allows you to buy it for $\max\lbrace a - kX, 0\rbrace$ yen.
Print the minimum amount of money Takahashi needs to buy all the items.
Constraints
- $1 \leq N \leq 2 \times 10^5$
- $1 \leq K, X \leq 10^9$
- $1 \leq A_i \leq 10^9$
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
$N$ $K$ $X$
$A_1$ $A_2$ $\ldots$ $A_N$
Output
Print the answer.
Sample Input 1
5 4 7
8 3 10 5 13
Sample Output 1
12
By using $1$ coupon on the $1$-st item, $1$ coupon on the $3$-rd item, and $2$ coupons on the $5$-th item, Takahashi can:
- buy the $1$-st item for $\max\lbrace A_1-X, 0 \rbrace = 1$ yen,
- buy the $2$-nd item for $\max\lbrace A_2, 0 \rbrace = 3$ yen,
- buy the $3$-rd item for $\max\lbrace A_3-X, 0 \rbrace = 3$ yen,
- buy the $4$-th item for $\max\lbrace A_4, 0 \rbrace = 5$ yen,
- buy the $5$-th item for $\max\lbrace A_5-2X, 0 \rbrace = 0$ yen,
for a total of $1 + 3 + 3 + 5 + 0 = 12$ yen, which is the minimum possible.
Sample Input 2
5 100 7
8 3 10 5 13
Sample Output 2
0
Sample Input 3
20 815 60
2066 3193 2325 4030 3725 1669 1969 763 1653 159 5311 5341 4671 2374 4513 285 810 742 2981 202
Sample Output 3
112
发现如果减少后没有小于 0,那么可以直接减 $X$。所以我们先把能减的减掉。
剩下的,把他从大到小排序完后,尽量减前面的就可以了。
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N=2e5+5;
int n,k,x,a[N];
LL s,ret;
int cmp(int x,int y)
{
return x>y;
}
int main()
{
scanf("%d%d%d",&n,&k,&x);
for(int i=1;i<=n;i++)
{
scanf("%d",a+i);
ret+=a[i]/x;
a[i]%=x;
s+=a[i];
}
sort(a+1,a+n+1,cmp);
if(k<ret)
printf("%lld",1LL*(ret-k)*x+s);
else
{
for(int i=1;i<=n&&i<=k-ret;i++)
s-=a[i],a[i]=0;
printf("%lld",s);
}
}
[ABC246C] Coupon的更多相关文章
- Recruit Coupon Purchase Winner's Interview: 2nd place, Halla Yang
Recruit Coupon Purchase Winner's Interview: 2nd place, Halla Yang Recruit Ponpare is Japan's leading ...
- PAT1037:Magic Coupon
1037. Magic Coupon (25) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue The magi ...
- A1037. Magic Coupon
The magic shop in Mars is offering some magic coupons. Each coupon has an integer N printed on it, m ...
- 1037 Magic Coupon (25 分)
1037 Magic Coupon (25 分) The magic shop in Mars is offering some magic coupons. Each coupon has an i ...
- PAT 1037 Magic Coupon[dp]
1037 Magic Coupon(25 分) The magic shop in Mars is offering some magic coupons. Each coupon has an in ...
- django中使用时间帅选报RuntimeWarning: DateTimeField Coupon.valid_begin_date received a naive datetime (2018-08-16 20:51:40.135425) while time zone support is active.
今天在使用当前时间进行筛选数据时出现了RuntimeWarning: DateTimeField Coupon.valid_begin_date received a naive datetime ( ...
- PAT 甲级 1037 Magic Coupon
https://pintia.cn/problem-sets/994805342720868352/problems/994805451374313472 The magic shop in Mars ...
- Magento--判断checkout中是否使用了coupon code
在checkout页面中,如果想判断顾客是否有使用coupon code,可以通过checkout session来进行判断.以下代码会返回checkout中使用的coupon code或者返回空(当 ...
- A1037 Magic Coupon (25 分)
一.技术总结 这也是一个贪心算法问题,主要在于想清楚,怎么解决输出和最大,两个数组得确保符号相同位相乘,并且绝对值尽可能大. 可以用两个vector容器存储,然后排序从小到大或是从大到小都可以,一次从 ...
- 使用Hybris的customer coupon进行促销活动(promotion)
登录Backoffice,在Coupon菜单里创建一个新的类型为Customer Coupon的优惠券: 在菜单Marketing->Promotion Rules里,创建一条新的促销规则Pro ...
随机推荐
- DORA指标:公司业务成果的“占卜师”
2009 年,受 John Allspaw 和 Paul Hammonds 在 Velocity 上演讲的启发,Patrick Debois 组织了一次名为"DevOps Days" ...
- 电气工程师必学------CODESYS v3.5 入门学习笔记(一)
一.新建工程 打开软件新建工程,如图 此教程只是入门练习,所以这里一般情况下都是创建的Standard project,也就是标准工程.窗口下方可以设置工程名称与存放位置. 紧接着是选择设备与编译语言 ...
- Go语言系列——11-数组和切片、12-可变参数函数、13-Maps、14-字符串、15-指针、16-结构体、17-方法、18-接口(一)、19-接口(二)、19-自定义集合类型、20-并发入门
文章目录 11-数组和切片 数组 数组的声明 数组是值类型 数组的长度 使用 range 迭代数组 多维数组 切片 创建一个切片 切片的修改 切片的长度和容量 使用 make 创建一个切片 追加切片元 ...
- Apifox调用文件下载或Excel导出接口
点发送下面这个发送并下载就行了,,,,,在网上搜了一下午愣是没看到,,,,,,
- Skywalking APM监控系列(二、Mysql、Linux服务器与前端JS接入Skywalking监听)
前言 上篇我们介绍了Skywalking的基本概念与如何接入.Net Core项目,感兴趣可以去看看: Skywalking APM监控系列(一丶.NET5.0+接入Skywalking监听) 本篇我 ...
- P4899 [IOI2018] werewolf 狼人 题解
P4899 [IOI2018] werewolf 狼人 题解 题目描述 省流: \(n\) 个点,\(m\) 条边,\(q\) 次询问,对于每一次询问,给定一个起点 \(S\) 和终点 \(T\) , ...
- 优化预算管理流程:Web端实现预算编制的利器
本文由葡萄城技术团队原创并首发.转载请注明出处:葡萄城官网,葡萄城为开发者提供专业的开发工具.解决方案和服务,赋能开发者. 前言:什么是预算和预算编制 预算 预算是企业在预测.决策的基础上,以数量和金 ...
- 18. 从零开始编写一个类nginx工具, 主动式健康检查源码实现
wmproxy wmproxy将用Rust实现http/https代理, socks5代理, 反向代理, 静态文件服务器,后续将实现websocket代理, 内外网穿透等, 会将实现过程分享出来, 感 ...
- 一个简单高效低内存的.NET操作Excel开源框架 - MiniExcel
前言 日常工作中经常与数据打交道的同学肯定会难以避免对Excel的一些数据操作如导入.导出等,但是当对一些大数据量操作Excel时经常会遇到一个常见的问题内存溢出.今天给大家推荐一个简单.高效.低内存 ...
- QGradient渐变填充
QGradient渐变填充 QGradient (一)简介 (二)枚举类型 1.spread 2.CoordinateMode 3.type (三)常用函数 1.coordinateMode() 2. ...