#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 houses. Each house has a unique house number, starting from up to .
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 , representing the number of sensors and the number of houses.
In the next lines, each line contains two positive integers and , meaning the position and the total number of calls detected by sensor . We say that a sensor is at position if and only if it is placed between house and house .
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 of the testdata, , , , .
- For of the testdata, , , , .
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
京公网安备 11011102002149号