아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

The Spellbook

면접 대비

시간 제한2초메모리 제한512 MB

요약
마나 비용이 있는 n개의 주문과 초기 MP m이 주어질 때, 최대 k만큼 비용을 줄이고 모든 주문을 정확히 한 번씩 사용하기 위해 필요한 최소 휴식 시간을 구한다.
난이도

보통10점 중 6점

유형
그리디, 정렬, 수학, 이분 탐색
정답자
아직 제출이 없습니다

문제

You have a spellbook with nn spells. The spells are numbered by sequential integers from 11 to nn, and the spell ii (1≤i≤n1 \le i \le n) initially costs A_iA\_i MP (mana points). Initially you have mm MP.

Your goal is to cast each spell from the spellbook exactly once.

Before you start casting spells, you can eat up to kk 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 11.

After eating cookies, you start casting spells.

You can repeatedly choose and perform one of the following actions:

  • Choose an integer ii (1≤i≤n1 \le i \le n) and cast the spell ii. However, the current MP must be greater than or equal to A_iA\_i. This action takes zero time and decreases your MP by A_iA\_i.
  • If your MP is z<mz < m, you may take a rest to restore 11 MP. It takes m−zm - z seconds (for example, if m=5m = 5 and z=2z = 2, you need to rest for 33 seconds to regenerate MP from 22 to 33).

Find the minimum amount of time you can spend to cast each of the nn spells exactly once. You are free to select the order of the spells.

입력

First line of the input contains three integers nn, mm and kk: the number of spells, the initial MP value and the number of cookies, respectively. The second line contains nn integers A_iA\_i: the initial costs of the spells in MP (1≤n≤1051 \le n \le 10^5, 1≤m≤1061 \le m \le 10^6, 1≤A_i≤m1 \le A\_i \le m, 0≤k≤∑_i=1nA_i0 \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 nn spells exactly once.

예제4

  1. 예제 1

    입력
    2 4 0
    2 4
    
    예상 출력
    3
    
  2. 예제 2

    입력
    3 9 6
    2 3 9
    
    예상 출력
    0
    
  3. 예제 3

    입력
    3 16 2
    6 9 9
    
    예상 출력
    21
    
  4. 예제 4

    입력
    2 1000000 0
    1000000 1000000
    
    예상 출력
    500000500000