CF289A.Polo the Penguin and Segments
普及-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Little penguin Polo adores integer segments, that is, pairs of integers [l; r] (l ≤ r).
He has a set that consists of n integer segments: [_l_1; _r_1], [_l_2; _r_2], ..., [l__n; r__n]. We know that no two segments of this set intersect. In one move Polo can either widen any segment of the set 1 unit to the left or 1 unit to the right, that is transform [l; r] to either segment [l - 1; r], or to segment [l; r + 1].
The value of a set of segments that consists of n segments [_l_1; _r_1], [_l_2; _r_2], ..., [l__n; r__n] is the number of integers x, such that there is integer j, for which the following inequality holds, l__j ≤ x ≤ r__j.
Find the minimum number of moves needed to make the value of the set of Polo's segments divisible by k.
小企鹅 Polo 非常喜爱整数线段,即形如 ([l, r])(其中 (l \leq r))的整数对。
他拥有一个由 (n) 个整数线段组成的集合:([l_1, r_1],\ [l_2, r_2],\ \dots,\ [l_n, r_n])。已知该集合中任意两个线段互不相交。在一次操作中,Polo 可以将集合中的任意一个线段向左扩展 1 单位或向右扩展 1 单位,即把 ([l, r]) 变为 ([l - 1, r]) 或 ([l, r + 1])。
由 (n) 个线段 ([l_1, r_1],\ [l_2, r_2],\ \dots,\ [l_n, r_n]) 构成的线段集合的值,定义为满足如下条件的整数 (x) 的个数:存在某个整数 (j),使得不等式 (l_j \leq x \leq r_j) 成立。
求使 Polo 的线段集合的值能被 (k) 整除所需的最少操作次数。
输入格式
The first line contains two integers n and k (1 ≤ n, k ≤ 105). Each of the following n lines contain a segment as a pair of integers l__i and r__i ( - 105 ≤ l__i ≤ r__i ≤ 105), separated by a space.
It is guaranteed that no two segments intersect. In other words, for any two integers i, j (1 ≤ i < j ≤ n) the following inequality holds, min(r__i, r__j) < max(l__i, l__j).
第一行包含两个整数 n 和 k(1≤n,k≤105)。接下来的 n 行每行包含一个线段,由一对整数 li 和 ri(−105≤li≤ri≤105)表示,两个整数之间用空格分隔。
保证任意两个线段互不相交。换言之,对任意两个整数 i,j(1≤i<j≤n),均满足以下不等式:min(ri,rj)<max(li,lj)。
输出格式
In a single line print a single integer — the answer to the problem.
在一行中输出一个整数——该问题的答案。
输入输出样例
输入#1
2 3 1 2 3 4
输出#1
2
输入#2
3 7 1 2 3 3 4 7
输出#2
0
输入解题思路,AI测评打分。不知道怎么写?