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;
}

转载于:https://www.cnblogs.com/-yjun/p/10427644.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值