No.2329 Nafmo Cheats
タグ : / 解いたユーザー数 78
作問者 :
hikikomori
sepa38
Problem Statement
Nafmo is taking part in an unusual game at a casino.
The game is played with $N$ playing-card-like cards.
The $N$ cards have the numbers $A_1,A_2, \dots,A_N$ written on their front faces, respectively, and their back faces are indistinguishable.
The participants, $1$ person at a time, determine their scores by following the procedure below. Among the participants with a score of at most $M$, the one with the highest score wins.
Nafmo, who has been granted supernatural powers, can use clairvoyance. He can draw a card with any number he aims for from among the face-down cards.
Using his powers, Nafmo obtained the maximum score he could achieve among scores of at most $M$.
What score did Nafmo obtain?
Rules of the game
- The initial score is $0$ points.
- If the number of cards drawn so far is less than $K$, choose whether or not to draw a card.
- If drawing a card, choose $1$ card from among the $N$ shuffled, indistinguishable cards lying face down.
- Add the number written on the chosen card to the score.
- Put the card back and return to step 2.
- The procedure ends once $K$ cards have been drawn or the choice not to draw a card has been made.
Input
$N\ M \ K$ $A_1\ A_2\ \dots \ A_N$
- $1 \leq N \leq 100$
- $0 \leq M \leq 6 \times \max(A)$
- $1 \leq K \leq 6$
- $0 \leq A_i \leq 10^9$
- All inputs are integers.
Output
Print the score Nafmo obtained to standard output.
Sample
Sample 1
Input
3 10 4 1 2 3
Output
10
In this case, Nafmo can achieve a score of $10$ by drawing cards $4$ times: $2,2,3,3$. Since $M=10$, the score must be at most $10$, so the answer is $10$.
Sample 2
Input
10 0 6 1 2 3 4 5 6 7 8 9 10
Output
0
In this case, Nafmo's score must be at most $0$ points, so he does not draw even $1$ card.
Sample 3
Input
2 1 6 1 2
Output
1
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。