Educational Codeforces Round 60 (Rated for Div. 2) B. Emotes
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
There are
n
n
emotes in very popular digital collectible card game (the game is pretty famous so we won't say its name). The
i
i
-th emote increases the opponent's happiness by
a
i
ai
units (we all know that emotes in this game are used to make opponents happy).
You have time to use some emotes only
m
m
times. You are allowed to use any emotion once, more than once, or not use it at all. The only restriction is that you cannot use the same emote more than
k
k
times in a row (otherwise the opponent will think that you're trolling him).
Note that two emotes
i
i
and
j
j
(
i≠j
i≠j
) such that
a
i
a
j
ai=aj
are considered different.
You have to make your opponent as happy as possible. Find the maximum possible opponent's happiness.
Input
The first line of the input contains three integers
n,m
n,m
and
k
k
(
2≤n≤2⋅
10
5
2≤n≤2⋅105
,
1≤k≤m≤2⋅
10
9
1≤k≤m≤2⋅109
) — the number of emotes, the number of times you can use emotes and the maximum number of times you may use the same emote in a row.
The second line of the input contains
n
n
integers
a
1
,
a
2
,…,
a
n
a1,a2,…,an
(
1≤
a
i
≤
10
9
1≤ai≤109
), where
a
i
ai
is value of the happiness of the
i
i
-th emote.
Output
Print one integer — the maximum opponent's happiness if you use emotes in a way satisfying the problem statement.
Examples
Input
Copy
6 9 2
1 3 3 7 4 2
Output
Copy
54
Input
Copy
3 1000000000 1
1000000000 987654321 1000000000
Output
Copy
1000000000000000000
Note
In the first example you may use emotes in the following sequence:
4,4,5,4,4,5,4,4,5
4,4,5,4,4,5,4,4,5
.
题解:给你n个数,可以从中取m个数,可以重复取用,对同一个数最多可以连续取用k次,位置不同但值相同算两个数.
这里我们可以分成两种情况,第一种,值最大且相同的数有两个,如 1000000000 987654321 1000000000,那就没有k次的限制,可以只用最大数.
第二种:最大数只有一个,那就再找一个第二大的数,用k次最大数+一次最小数,这样总和会最大.
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int main()
{
ll n,tmp;
ll m,k,a=0,b=0;
scanf("%I64d%I64d%I64d",&n,&m,&k);
for(int i=1;i<=n;i++){
scanf("%I64d",&tmp);
if(tmp > a){
b=a;a=tmp;
}
else if(tmp > b) b=tmp;
//cout<<a<<" "<<b<<endl;
}
//int cnt=0;
if(a==b) printf("%I64d\n",m*a);
else
printf("%I64d\n",m/(k+1)*(k*a+b)+m%(k+1)*a);
//cout << "Hello world!" << endl;
return 0;
}
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Linux glibc自带哈希表的用例及性能测试
· 深入理解 Mybatis 分库分表执行原理
· 如何打造一个高并发系统?
· .NET Core GC压缩(compact_phase)底层原理浅谈
· 现代计算机视觉入门之:什么是图片特征编码
· 手把手教你在本地部署DeepSeek R1,搭建web-ui ,建议收藏!
· Spring AI + Ollama 实现 deepseek-r1 的API服务和调用
· 数据库服务器 SQL Server 版本升级公告
· 程序员常用高效实用工具推荐,办公效率提升利器!
· C#/.NET/.NET Core技术前沿周刊 | 第 23 期(2025年1.20-1.26)