시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
---|---|---|---|---|---|
2 초 | 512 MB | 1 | 1 | 1 | 100.000% |
You have a spellbook with $n$ spells. The spells are numbered by sequential integers from $1$ to $n$, and the spell $i$ ($1 \le i \le n$) initially costs $A_i$ MP (mana points). Initially you have $m$ MP.
Your goal is to cast each spell from the spellbook exactly once.
Before you start casting spells, you can eat up to $k$ cookies. Eating a cookie takes zero time. Each time you eat a cookie, you can choose a spell with a positive cost and reduce that cost by $1$.
After eating cookies, you start casting spells.
You can repeatedly choose and perform one of the following actions:
Find the minimum amount of time you can spend to cast each of the $n$ spells exactly once. You are free to select the order of the spells.
First line of the input contains three integers $n$, $m$ and $k$: the number of spells, the initial MP value and the number of cookies, respectively. The second line contains $n$ integers $A_i$: the initial costs of the spells in MP ($1 \le n \le 10^5$, $1 \le m \le 10^6$, $1 \le A_i \le m$, $0 \le k \le \sum\limits_{i=1}^n A_i$).
Print one integer: the minimum amount of time it takes to cast each of the $n$ spells exactly once.
2 4 0 2 4
3
3 9 6 2 3 9
0
3 16 2 6 9 9
21
2 1000000 0 1000000 1000000
500000500000