#P7260. [COCI 2009/2010 #3] RAZGOVOR

[COCI 2009/2010 #3] RAZGOVOR

Description

Cute Village has only one long street stretching from east to west, with mm houses. Each house has a unique house number, starting from 11 up to mm.

A recent snowstorm destroyed most of the telephone lines, so the mayor funded the construction of a new telephone line network. Mirko is very interested in how widely this new telephone network is used, so he installed special sensors at some positions.

A sensor can detect any phone call between two houses such that one house is to the east of the sensor and the other house is to the west of the sensor.

At the end of the first month, Mirko removed all sensors and now wants to know the minimum possible number of phone calls that could have been made during that month.

Input Format

The first line contains two positive integers n,mn, m, representing the number of sensors and the number of houses.

In the next nn lines, each line contains two positive integers PiP_i and CiC_i, meaning the position and the total number of calls detected by sensor ii. We say that a sensor is at position PiP_i if and only if it is placed between house PiP_i and house Pi+1P_i + 1.

There is at most one sensor at the same position.

Output Format

Output one positive integer, the minimum number of calls.

3 4
3 1
2 2
1 1

2
2 3
1 23
2 17

23
3 9
7 2
8 3
3 4

5

Hint

Constraints

  • For 50%50\% of the testdata, 1n1031 \le n \le 10^3, 1Ci1031 \le C_i \le 10^3, n<m109n < m \le 10^9, 1Pi<M1 \le P_i < M.
  • For 100%100\% of the testdata, 1n1051 \le n \le 10^5, 1Ci1091 \le C_i \le 10^9, n<m109n < m \le 10^9, 1Pi<M1 \le P_i < M.

Notes

Translated from COCI 2009-2010 #3 T4 RAZGOVOR, full score 100. Each test point is worth 10 points, with 10 test points in total.

Translated by ChatGPT 5