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. Docker 安装Redis 无法使用配置文件设置密码问题

    背景 最近开发需要使用各种组件,如果都到开发机上安装,会占用电脑资源较多.所以使用docker容器来安装这些组件.例如 redis .mongodb.mysql.rabitmq.elasticsear ...

  2. Windows 虚拟地址 到底是如何映射到 物理地址 的?

    一:背景 1. 讲故事 我发现有很多的 .NET程序员 写了很多年的代码都没弄清楚什么是 虚拟地址,更不用谈什么是 物理地址 以及Windows是如何实现地址映射的了?这一篇我们就来聊一聊这两者之间的 ...

  3. UM 百度富文本编辑器上传报错

    看下报错信息 这三张图记录了当时,上传图片 遇见的报错信息 最终解决方案 我把UM下jsp文件下的ueditor-mini.jar包拷贝到WEB_INF下的lib文件夹下,就成功了. maven的话把 ...

  4. 从内核世界透视 mmap 内存映射的本质(原理篇)

    本文基于内核 5.4 版本源码讨论 之前有不少读者给笔者留言,希望笔者写一篇文章介绍下 mmap 内存映射相关的知识体系,之所以迟迟没有动笔,是因为 mmap 这个系统调用看上去简单,实际上并不简单, ...

  5. Linux中python更换pip源

    Linux中python更换pip源 执行以下命令,更换为阿里源: echo " [global] trusted-host = mirrors.aliyun.com index-url = ...

  6. Netty集成HTTP的GET和POST通讯

    核心就是ChannelInitializer的实现使用http 消息解码器 package com.coremain.handler; import io.netty.channel.ChannelI ...

  7. MySQL——MySQL面试题

    文章目录 数据库基础知识 为什么要使用数据库 什么是SQL? 什么是MySQL? 数据库三大范式是什么 mysql有关权限的表都有哪几个 MySQL的binlog有有几种录入格式?分别有什么区别? 数 ...

  8. OPPO主题组件开发 - 组件内容自适应

    OPPO桌面有 3*5.3*6.4*5.4*6.5*5.5*6 等布局,随着布局不同,组件大小也会发生改变:不同型号手机分辨率不同,组件大小也不一致.这就要求组件内容做到自适应. 说明 OPPO主题组 ...

  9. Informix 4gl错误代码信息和更正

    (一)Informix信息和更正 出版日期:6 1996 年 年 1 11 月 0 成功. 操作成功.当 SQL 语句成功地执行时,数据库服务器把这个 SQLCODE 值返回给应用程序. 100 没有 ...

  10. RocketMQ为什么要保证订阅关系一致

    这篇文章,笔者想聊聊 RocketMQ 最佳实践之一:保证订阅关系一致. 订阅关系一致指的是同一个消费者 Group ID 下所有 Consumer 实例所订阅的 Topic .Tag 必须完全一致. ...