A973.Springboards--Gold
省选/NOI-
通过率:0%
时间限制:1.00s
内存限制:128MB
题目描述
Bessie is in a 2D grid where walking is permitted only in directions parallel
to one of the coordinate axes. She starts at the point (0,0) and wishes to
reach (N,N) (1≤N≤109). To help her out, there are P (1≤P≤105) springboards on the grid. Each springboard is at a fixed point
(x1,y1) and if Bessie uses it, she will land at a point (x2,y2).
Bessie is a progress-oriented cow, so she only permits herself to walk up or
right, never left nor down. Likewise, each springboard is configured to never
go left nor down. What is the minimum distance Bessie needs to walk?
输入格式
Output a single integer, the minimum distance Bessie needs to walk to reach
(N,N).
输出格式
The fist line contains two space-separated integers N and P.
The next P lines each contains four integers, x1, y1, x2, y2,
where x1≤x2 and y1≤y2.
All springboard and target locations are distinct.
输入输出样例
输入#1
3 2 0 1 0 2 1 2 2 3
输出#1
3
说明/提示
- Test cases 2-5 satisfy P≤1000.
- Test cases 6-15 satisfy no additional constraints.