首页 > 其他分享 >Coupon

Coupon

时间:2022-09-30 19:00:07浏览次数:36  
标签:buy rbrace leq Coupon yen item int

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$。所以我们先把能减的减掉。 剩下的,把他从大到小排序完后,尽量减前面的就可以了。 ```cpp #include 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

标签:buy,rbrace,leq,Coupon,yen,item,int
From: https://www.cnblogs.com/mekoszc/p/16745868.html

相关文章

  • PAT_A 1037 Magic Coupon
    PAT_A1037MagicCoupon分析尽量增大总回报值即可得到结果。PAT_A1037MagicCoupon题目的描述ThemagicshopinMarsisofferingsomemagiccoupons.Eachcoup......
  • coupon
    Inmarketing,acouponisaticketordocumentthatcanberedeemedforafinancialdiscountorrebatewhenpurchasingaproduct.Customarily,couponsareissu......
  • system desing 系统设计(八):视频流videos stream和优惠券coupon/秒杀/抢红包等系统设
    1、印象中从2017年开始抖音火了,直接带动了视频流这种UGC的火爆,江湖传闻抖音的DAU和平均用户时长已经超过了wechat,实现了弯道超车,实在是后生可畏!对于这种视频站点,可能的......