Candies

시간 제한1초메모리 제한1024 MB

요약
보보 1은 게임 전에 최대 y개의 사탕을 미리 가질 수 있고, 매 라운드 최솟값을 가진 보보가 x개를 받을 때 보보 1의 최종 사탕 수의 최댓값을 구한다.
난이도

보통10점 중 7점

유형
이분 탐색, 그리디, 정렬, 시뮬레이션
정답자
아직 제출이 없습니다

문제

nn bobo are playing a game about candies. bobo are labeled by 1,2,…,n1, 2, \dots, n for convenience. Initially, the ii-th bobo has a_ia\_i candies in hand.

The game is played in mm rounds. In each round, the bobo who has the least number of candies currently is awarded with xx candies. If two or more bobo have the same number of candies, the bobo with the smallest label gets the prize.

The 11-st bobo is their leader. So he can get at most yy more candies from some unknown source before the start of the game. Now he wonder the maximum number of candies he can have after the mm rounds.

입력

The first line contains 44 integers n,m,x,yn, m, x, y (1≤n,m≤200000,1≤x,y≤1091 \leq n, m \leq 200000, 1 \leq x, y \leq 10^9).

The second line contains nn integers a_1,a_2,…,a_na\_1, a\_2, \dots, a\_n (1≤a_i≤1091 \leq a\_i \leq 10^9).

출력

A single integer denotes the maximum number of candies.

예제1

  1. 예제 1

    입력
    2 1 2 2
    1 2
    
    예상 출력
    4