[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 ...
随机推荐
- Doris 再次启动FE失败的思考
Doris再次启动FE失败的思考 背景描述 在昨天已经成功下载安装最新稳定版docker.拉取doris-0.15.0版本的镜像.将镜像挂载道本地Doris源码目录.完成了doris的编译之后,今天在 ...
- 通过Scrum实现最大生产力的五种方法
在数字化.信息化.智能化蓬勃发展的今天,敏捷开发和Scrum已成为重塑项目管理的重要方式. 敏捷是一种体现不同方法的思维方式,包括了Scrum,看板,极限编程(XP).精益开发等众多框架. Scrum ...
- 算法笔记_python
目录 算法 概念 时间复杂度 空间复杂度 递归原理 顺序查找 二分查找 列表排序 LowB 三人组 冒泡排序 选择排序 插入排序 NB三人组 快速排序 堆排序 归并排序 NB三人组小结 总结 其他排序 ...
- IDEA集成码云gitee
参考链接:https://blog.csdn.net/bing_bg/article/details/106437008 1.下载安装git https://git-scm.com/download ...
- 给你的模糊测试开开窍——定向灰盒模糊测试(Directed Greybox Fuzzing)综述
本文系原创,转载请说明出处 Please Subscribe Wechat Official Account:信安科研人,获取更多的原创安全资讯 原论文:<The Progress, Cha ...
- 小知识:调整OCI实例的时区
之前在随笔中<Linux (RHEL)修改时区> 介绍了时区修改方法. 默认OCI实例中,时区是GMT,在国内用看着这个时区就是很别扭的事情,于是修改时区,实测无需配置 /etc/sysc ...
- 宏观上理解blazor中的表单验证
概述 表单验证的最终效果大家都懂,这里不阐述了,主要从宏观角度说说blazor中表单验证框架涉及到的类,以及它们是如何协作的,看完这个,再看官方文档也许能更轻松点. blazor中的验证框架分为两部分 ...
- Debian12安装.NET7 SDK
Debian,作为最受欢迎的 Linux 发行版之一,于 2023 年 6 月 10 日正式发布了其最新版本 Debian 12,代号"Bookworm".Debian 12 带来 ...
- FFmpeg: How To Convert MP4 Video To MP3 Audio?
FFmpeg: How To Convert MP4 Video To MP3 Audio? Learn how to Convert an MP4 Video to MP3 Audio wit ...
- MySQL低配数据库被大量数据导入时KO
在一个低配MySQL数据库(笔记本电脑虚机环境,虚机配置2CPU/3G内存),在3000万级别的大量数据LOAD DATA方式导入时,坚持一小时后,终于被KO了,甚至没写下任何有用的日志,只是在操作界 ...