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;
}
posted @ 2019-02-24 20:06  _yjun  阅读(379)  评论(0编辑  收藏  举报