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的更多相关文章

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

  2. PAT1037:Magic Coupon

    1037. Magic Coupon (25) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue The magi ...

  3. A1037. Magic Coupon

    The magic shop in Mars is offering some magic coupons. Each coupon has an integer N printed on it, m ...

  4. 1037 Magic Coupon (25 分)

    1037 Magic Coupon (25 分) The magic shop in Mars is offering some magic coupons. Each coupon has an i ...

  5. PAT 1037 Magic Coupon[dp]

    1037 Magic Coupon(25 分) The magic shop in Mars is offering some magic coupons. Each coupon has an in ...

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

  7. PAT 甲级 1037 Magic Coupon

    https://pintia.cn/problem-sets/994805342720868352/problems/994805451374313472 The magic shop in Mars ...

  8. Magento--判断checkout中是否使用了coupon code

    在checkout页面中,如果想判断顾客是否有使用coupon code,可以通过checkout session来进行判断.以下代码会返回checkout中使用的coupon code或者返回空(当 ...

  9. A1037 Magic Coupon (25 分)

    一.技术总结 这也是一个贪心算法问题,主要在于想清楚,怎么解决输出和最大,两个数组得确保符号相同位相乘,并且绝对值尽可能大. 可以用两个vector容器存储,然后排序从小到大或是从大到小都可以,一次从 ...

  10. 使用Hybris的customer coupon进行促销活动(promotion)

    登录Backoffice,在Coupon菜单里创建一个新的类型为Customer Coupon的优惠券: 在菜单Marketing->Promotion Rules里,创建一条新的促销规则Pro ...

随机推荐

  1. [远程Call]32位远程多参数带返回调用

    [远程Call]32位远程多参数带返回调用 引子 在Windows上可以使用CreateRemoteThread实现远程Call,但是有不带返回值且只能传递一个参数的限制. 解决思路 将多个参数利用V ...

  2. 架构师必会之-DBA级问题的数据库底层设计思想

    大家好,我是sulny_ann,这期想跟大家分享一下我之前在面试里面问过比较难的数据库相关的问题. 大家经常也在调侃后端好像就是技术数据库的增删改查,所以作为后端开发,你对应数据库这一块掌握的怎么样, ...

  3. 云服务器中Linux如何安装宝塔面板?

    作者:西瓜程序猿 主页传送门:https://www.cnblogs.com/kimiliucn 官方使用手册:https://www.kancloud.cn/chudong/bt2017/42420 ...

  4. java类序列化和反序列化

    参考:https://zhuanlan.zhihu.com/p/144535172?utm_id=0 https://blog.csdn.net/qq_42617455/article/details ...

  5. numpy中矩阵的逆,求解,特征值,特征向量

    逆:numpy.linalg.inv() # 求矩阵的逆import numpy as npa=np.mat('1 0;0 1')#生成一个矩阵print(type(a))b=np.linalg.in ...

  6. 部分网页中仅供浏览的pdf文件下载方法

    现在越来越多的网站提供的PDF资料只能在线浏览,不提供下载功能,实际上仅仅是通过网页PDF浏览插件来访问文件资源,如果能够获取到该文件的访问地址,就可以访问下载. 以Firefox浏览器访问某大学网站 ...

  7. Ds100p -「数据结构百题」11~20

    11.P3203 [HNOI2010]弹飞绵羊 某天,\(Lostmonkey\) 发明了一种超级弹力装置,为了在他的绵羊朋友面前显摆,他邀请小绵羊一起玩个游戏. 游戏一开始,\(Lostmonkey ...

  8. 在线问诊 Python、FastAPI、Neo4j — 生成 Cypher 语句

    目录 构建节点字典 构建Cypher CQL语句 Test 这边只是为了测试,演示效果和思路,实际应用中,可以通过NLP构建CQL 接上一篇的问题分类 question = "请问最近看东西 ...

  9. Django框架——模型层单表操作、模型层多表操作、模型层常用和非常用字段和参数、模型层进阶

    文章目录 1 模型层-单表操作 一 ORM简介 二 单表操作 2.1 创建表 1 创建模型 2 更多字段 3 更多参数 4 settings配置 5 增加,删除字段 2.2 添加表纪录 2.3 查询表 ...

  10. linux常用命令(七)

    用于系统内信息交流的相关命令 echo mesg wall write echo:在显示器上显示文字 命令语法:echo[选项] [字符串] 选项 选项含义 -n 表示输出文字后不换行 例子:将文本& ...