Logo
(追記) (追記ここまで)

33186번 - Pistons 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 2048 MB999100.000%

문제

Maryam, a famous mathematician, recently has bought an old vintage car. This car uses a combustion engine to generate the power needed to move the car. Inside the engine, there are $n$ cylinders of length $m$ and inside each cylinder, there is a piston constantly moving up and down. All pistons move independently and at the same speed. At any given time, the position of a piston inside a cylinder can be shown with an integer from 0ドル$ to $m,ドル which also describes the area of the cylinder occupied by the piston. A piston instantly changes its direction when it reaches the top (position $m$) or bottom (position 0ドル$) of its cylinder.

Maryam managed to determine the position and direction of all the pistons at a specific time. Now she is curious about the maximum total area occupied by all the pistons. Help Maryam find out this value.

입력

The first line of input contains two integers $n$ and $m$ (1ドル \le n \le 10^5,ドル 1ドル \le m \le 10^6$), describing the number of pistons and the length of cylinders, respectively. Each of the next $n$ lines describe the position and direction of a single piston. The $(i + 1)$th line of the input contains an integer $p_i$ (0ドル \le p_i \le m$), and a character $d_i$ ($d_i \in \{$U, D$\}$), the initial position of the $i$th piston and its direction (Up or Down), respectively.

출력

Print a single integer, the maximum total area occupied by all the pistons.

제한

예제 입력 1

2 5
2 U
5 D

예제 출력 1

7

예제 입력 2

4 6
0 U
0 D
6 U
3 U

예제 출력 2

15

힌트

출처

ICPC > Regionals > Asia West Continent > Iran > 2023 ICPC Asia Tehran Regional Contest I번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /