CF1120F.Secret Letters

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Little W and Little P decided to send letters to each other regarding the most important events during a day. There are nn events during a day: at time moment tit_i something happens to the person pip_i ( pip_i is either W or P, denoting Little W and Little P, respectively), so he needs to immediately send a letter to the other person. They can send a letter using one of the two ways:

  • Ask Friendly O to deliver the letter directly. Friendly O takes dd acorns for each letter.
  • Leave the letter at Wise R's den. Wise R values free space, so he takes cTc \cdot T acorns for storing a letter for a time segment of length TT . The recipient can take a letter from Wise R either when he leaves his own letter at Wise R's den, or at time moment tn+1t_{n + 1} , when everybody comes to Wise R for a tea. It is not possible to take a letter from Wise R's den at other time moments. The friends can store as many letters at Wise R's den as they want, paying for each one separately.

Help the friends determine the minimum possible total cost of sending all letters.

输入格式

The first line contains three integers n,c,dn, c, d ( 1n1051 \leq n \leq 10^5 , 1c1021 \leq c \leq 10^2 , 1d1081 \leq d \leq 10^8 ) — the number of letters, the cost of storing a letter for one time unit at Wise R's den and the cost of delivering a letter via Friendly O.

The next nn describe the events. The ii -th of them contains an integer tit_i and a character pip_i ( 0ti1060 \leq t_i \leq 10^6 , pip_i is either W or P) — the time the ii -th event happens and the person the event happens to.

The last line contains a single integer tn+1t_{n + 1} ( 0tn+11060 \leq t_{n+1} \leq 10^6 ) — the time when everybody comes to Wise R for a tea and takes all remaining letters.

It is guaranteed that ti<ti+1t_i < t_{i + 1} for all ii from 11 to nn .

输出格式

Print a single integer — the minimum possible cost of delivery of all letters.

输入输出样例

  • 输入#1

    5 1 4
    0 P
    1 W
    3 P
    5 P
    8 P
    10
    

    输出#1

    16
    
  • 输入#2

    10 10 94
    17 W
    20 W
    28 W
    48 W
    51 P
    52 W
    56 W
    62 P
    75 P
    78 P
    87
    

    输出#2

    916
    

说明/提示

One of optimal solutions in the first example:

  • At time moment 0 Little P leaves the letter at Wise R's den.
  • At time moment 1 Little W leaves his letter at Wise R's den and takes Little P's letter. This letter is at the den from time moment 0 to time moment 1, it costs 11 acorn.
  • At time moment 3 Little P sends his letter via Friendly O, it costs 44 acorns.
  • At time moment 5 Little P leaves his letter at the den, receiving Little W's letter which storage costs 4 acorns.
  • At time moment 8 Little P leaves one more letter at the den.
  • At time moment 10 Little W comes to the den for a tea and receives the two letters, paying 5 and 2 acorns.

The total cost of delivery is thus 1+4+4+5+2=161 + 4 + 4 + 5 + 2 = 16 acorns.

首页