8439: Haybale Stacking

内存限制:128 MB 时间限制:1 S 标准输入输出
题目类型:传统 评测方式:文本比较 上传者:
提交:3 通过:1

题目描述

Feeling sorry for all the mischief she has caused around the farm recently, Bessie has agreed to help Farmer John stack up an incoming shipment of hay bales. She starts with N (1 <= N <= 1,000,000, N odd) empty stacks, numbered 1..N. FJ then gives her a sequence of K instructions (1 <= K <= 25,000), each of the form "A B", meaning that Bessie should add one new haybale to the top of each stack in the range A..B. For example, if Bessie is told "10 13", then she should add a haybale to each of the stacks 10, 11, 12, and 13. After Bessie finishes stacking haybales according to his instructions, FJ would like to know the median height of his N stacks -- that is, the height of the middle stack if the stacks were to be arranged in sorted order (conveniently, N is odd, so this stack is unique). Please help Bessie determine the answer to FJ's question.

贝茜对她最近在农场周围造成的一切恶作剧感到抱歉,她同意帮助农夫约翰把一批新到的干草捆堆起来。



开始时,共有 N 个空干草堆,编号 1∼N。



约翰给贝茜下达了 K 个指令,每条指令的格式为 A B,这意味着贝茜要在 A..B 范围内的每个干草堆的顶部添加一个新的干草捆。



例如,如果贝茜收到指令 10 13,则她应在干草堆 10,11,12,13 中各添加一个干草捆。



在贝茜完成了所有指令后,约翰想知道 N 个干草堆的中值高度——也就是说,如果干草堆按照高度从小到大排列,位于中间的干草堆的高度。



方便起见,N 一定是奇数,所以中间堆是唯一的。



请帮助贝茜确定约翰问题的答案。


输入格式



第一行包含 N 和 K。



接下来 K 行,每行包含两个整数 A,B,用来描述一个指令。

输出格式



输出完成所有指令后,N 个干草堆的中值高度。

输入样例 复制

7 4
5 5
2 4
4 6
3 5

输出样例 复制


数据范围与提示

样例解释

贝茜完成所有指令后,各堆高度为 0,1,2,3,3,1,0。



将各高度从小到大排序后,得到 0,0,1,1,2,3,3,位于中间的是 1。