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. 【LaTeX】基础介绍

    目录 TeX 和 LaTeX pdfTeX.XeTeX 和 LuaTeX 三者的介绍 各自的特性 参考资料 TeX 和 LaTeX Tex 是一个排版软件,而 LaTeX 是基于 TeX 开发的排版系 ...

  2. WPF学习 - 用鼠标移动、缩放、旋转图片(2)- 使用MatrixTransform

    在上一篇文章中,提到了以鼠标控制变换图片的方法. 这种方法在某种情况下可以,例如,直接在windows窗体上.但我发现,当把它封装到一个控件中的时候,它就不行了. 经过不断的尝试,我找到了一种更简单的 ...

  3. IDEA 配置桌面快捷方式

    IDEA 配置桌面快捷方式 目录 IDEA 配置桌面快捷方式 1.下载idea.tar解压 2.配置快捷方式 3.为什么要存放在这个目录? 1.下载idea.tar解压 tar xf ideaIC-2 ...

  4. 位图(bitmap)原理以及实现

    大家好,我是蓝胖子,我一直相信编程是一门实践性的技术,其中算法也不例外,初学者可能往往对它可望而不可及,觉得很难,学了又忘,忘其实是由于没有真正搞懂算法的应用场景,所以我准备出一个系列,囊括我们在日常 ...

  5. Solution Set -「ARC 113」

    「ARC 113A」A*B*C Link. 就是算 \(\sum_{i=1}^{k}\sum_{j=1}^{\lfloor\frac{k}{i}\rfloor}\lfloor\frac{k}{j\ti ...

  6. Linux升级至glibc-2.14步骤

    Linux升级至glibc-2.14步骤 查看gcc版本命令: strings /lib64/libc.so.6 |grep GLIBC_ glibc安装 首先, 点击此处下载glibc2.14下载, ...

  7. cmake构建32位应用程序

    1. 背景介绍 2. 工具介绍 3. 环境搭建 4. MinGW编译器版本 1. 背景介绍 最近需要使用第三方动态库文件G33DDCAPI.dll进行二次开发.由于这个动态库文件生成的时间比较早,且只 ...

  8. Django框架——路由控制、视图层

    文章目录 1 路由控制 一 Django中路由的作用 二 简单的路由配置 三 有名分组 四 路由分发 五 反向解析 六 名称空间 七 django2.0版的path 基本示例 path转化器 注册自定 ...

  9. ios ipa apple company 开发者账号申请分享攻略

    ios公司开发者账号申请分享攻略 好不容易终于申请下来了ios 公司开发者账号,真是一路艰辛和漫长啊,特别是对于远在大洋彼岸的大中华国家.以下我就分享一下这一路下来的经验,希望对于那些新手同仁们有所帮 ...

  10. 圆角android

    资源地址 <shape xmlns:android="http://schemas.android.com/apk/res/android"> <solid an ...