The Spellbook
면접 대비시간 제한2초메모리 제한512 MB
마나 비용이 있는 n개의 주문과 초기 MP m이 주어질 때, 최대 k만큼 비용을 줄이고 모든 주문을 정확히 한 번씩 사용하기 위해 필요한 최소 휴식 시간을 구한다.
문제
You have a spellbook with spells. The spells are numbered by sequential integers from to , and the spell () initially costs MP (mana points). Initially you have MP.
Your goal is to cast each spell from the spellbook exactly once.
Before you start casting spells, you can eat up to 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 .
After eating cookies, you start casting spells.
You can repeatedly choose and perform one of the following actions:
- Choose an integer () and cast the spell . However, the current MP must be greater than or equal to . This action takes zero time and decreases your MP by .
- If your MP is , you may take a rest to restore MP. It takes seconds (for example, if and , you need to rest for seconds to regenerate MP from to ).
Find the minimum amount of time you can spend to cast each of the spells exactly once. You are free to select the order of the spells.
입력
First line of the input contains three integers , and : the number of spells, the initial MP value and the number of cookies, respectively. The second line contains integers : the initial costs of the spells in MP (, , , ).
출력
Print one integer: the minimum amount of time it takes to cast each of the spells exactly once.