1. 程式人生 > >Educational Codeforces Round 60 (Rated for Div. 2) B. Emotes

Educational Codeforces Round 60 (Rated for Div. 2) B. Emotes

c++ pretty win happy pac contain bytes ict diff

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

Educational Codeforces Round 60 (Rated for Div. 2) B. Emotes