Aquatic Dragon

시간 제한3초메모리 제한2048 MB

요약
수영, 비행, 1회용 걸어가기 터널을 이용해 드래곤과 함께 섬 N에 도착하는 최소 시간을 구한다.
난이도

어려움10점 중 8점

유형
동적 계획법, 그리디, 누적 합
정답자
아직 제출이 없습니다

문제

You live in an archipelago consisting of NN islands (numbered from 11 to NN) laid out in a single line. Island ii is adjacent to island i+1i+ 1, for 1≤i<N1 ≤ i < N. Between adjacent islands ii and i+1i+ 1, there is a pair of one-directional underwater tunnels: one that allows you to walk from island ii to island i+1i+1 and one for the opposite direction. Each tunnel can only be traversed at most once.

You also have a dragon with you. It has a stamina represented by a non-negative integer. The stamina is required for the dragon to perform its abilities: swim and fly. Initially, its stamina is 00.

Your dragon’s stamina can be increased as follows. There is a magical shrine on each island ii that will immediately increase your dragon’s stamina by P_iP\_i (regardless the position of the dragon) when you visit island ii for the first time. This event takes no time.

When you are on an island, there are 33 moves that you can perform.

  • Swim with your dragon to an adjacent island if your dragon and you are on the same island. You can perform if your dragon’s stamina is at least DD. This move reduces your dragon’s stamina by DD, and it takes T_sT\_s seconds to perform.
  • Fly with your dragon to an adjacent island if your dragon and you are on the same island. You can perform this move if your dragon’s stamina is not 00. This move sets your dragon’s stamina to 00, and it takes T_fT\_f seconds to perform.
  • Walk alone without your dragon to an adjacent island through the underwater tunnel. This move takes T_wT\_w seconds to perform. Once you walk through this tunnel, it cannot be used again.

Note that both swimming and flying do not use tunnels.

Your dragon and you are currently on island 11. Your mission is to go to island NN with your dragon. Determine the minimum possible time to complete your mission.

입력

The first line consists of five integers NN DD T_sT\_s T_fT\_f T_wT\_w (2≤N≤200,0002 ≤ N ≤ 200\\, 000; 1≤D,T_s,T_f,T_w≤200,0001 ≤ D, T\_s, T\_f , T\_w ≤ 200\\, 000).

The second line consists of NN integers P_iP\_i (1≤P_i≤200,0001 ≤ P\_i ≤ 200\\, 000).

출력

Output an integer in a single line representing the minimum possible time to go to island NN with your dragon.

예제3

  1. 예제 1

    입력
    5 4 2 9 1
    1 2 4 2 1
    
    예상 출력
    28
    
  2. 예제 2

    입력
    5 4 2 1 1
    1 2 4 2 1
    
    예상 출력
    4
    
  3. 예제 3

    입력
    3 4 2 10 1
    3 1 2
    
    예상 출력
    16