[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 ...
随机推荐
- 【Java监控】使用SkyWalking监控Java服务
你的Java服务是如何监控的呢? 1.Null:监控?什么监控?我一个写代码的服务挂了跟我有什么关系? 2.命令行:服务挂了?内存泄漏?jstat jmap jcmd,还好不是我写的 3.撸代码:Ja ...
- 关于前后端交互,取header的尴尬
背景: 最近在写一个接口的时候,需求是这样的,上传excel,匹配项目有多少个字段匹配上了,如果匹配上了在单元格上标注绿色背景,然后返回excel文件和匹配的详细. 首先这个excel文件,后端是不会 ...
- 2023年了,复习了一下spring boot配置使用mongodb
前言 MongoDB是一个基于分布式文件存储的开源数据库系统,使用C++语言编写.它是一个介于关系数据库和非关系数据库之间的产品,具有类似关系数据库的功能,但又有一些非关系数据库的特点.MongoDB ...
- Python Flask 上下文管理源码分析
Python Flask 上下文管理源码分析 前言 Flask 上下文管理可以说是 Flask 非常具有特色的设计,它总共可分为 2 个大的方向: 应用上下文管理:通过 current_app 即可拿 ...
- 洛谷题解 | AT_abc321_c Primes on Interval
目录 题目翻译 题目描述 输入格式 输出格式 样例 #1 样例输入 #1 样例输出 #1 样例 #2 样例输入 #2 样例输出 #2 样例 #3 样例输入 #3 样例输出 #3 题目简化 题目思路 A ...
- C/C++中的ACM题目输入处理——简单易上手
这里就不按其他文章的以各种情况为分类方法,而是以方法本身为分类办法.因为有一些方法是不同情况通用的,比如已知数量数字的输入和未知数量数字的输入,其实可以用同一种办法. 输入 C/C++ :scanf正 ...
- ELK-WEB中文版化-redis高性能加速
1.ELK-WEB中文汉化版支持:(kibana所在机器执行)Kibana WEB平台所有的字段均显示为英文,目前5.x版本默认没有中文汉化版插件或者汉化包(7.x版本支持汉化默认有汉化),感谢Git ...
- Go 如何实现多态
在 Go 语言中,虽然没有经典的面向对象编程中的继承和多态的概念,但你可以通过接口(interface)来实现多态性.Go 语言鼓励组合和接口多态,这使得代码更加灵活和模块化.下面将详细介绍 Go 语 ...
- Java内部类与匿名类
内部类 定义: 一个类的内部又完整的嵌套了另一个类结构,被嵌套的类就被我们称为内部类,嵌套内部类的类被我们称为外部类 //外部类 class Outer { //内部类 class Inner { } ...
- DHorse(K8S的CICD平台)的实现原理
综述 首先,本篇文章所介绍的内容,已经有完整的实现,可以参考这里. 在微服务.DevOps和云平台流行的当下,使用一个高效的持续集成工具也是一个非常重要的事情.虽然市面上目前已经存在了比较成熟的自动化 ...