CodeForces 289A Polo the Penguin and Segments

开发者福利!热门AI工具限时免费用 购周边即赠Coding Plan Lite,Claude Code、Cursor等20+工具畅享,效率翻倍! 阅读详情

Polo the Penguin and Segments

Description

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: [l1; r1], [l2; r2], …, [ln; rn]. 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 [l1; r1], [l2; r2], …, [ln; rn] is the number of integers x, such that there is integer j, for which the following inequality holds, lj ≤ x ≤ rj.

Find the minimum number of moves needed to make the value of the set of Polo’s segments divisible by k.

Input

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 li and ri ( - 105 ≤ li ≤ ri ≤ 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(ri, rj) < max(li, lj).

Output

In a single line print a single integer — the answer to the problem.

Sample Input

Input

2 3
1 2
3 4

Output

2

Input

3 7
1 2
3 3
4 7

Output

0


我不得不说,恶心死了这样的题目
解释一大堆,绕来绕去,全是废话,还看不懂题意
没做出来,气死我了,看了半天题意没搞懂
百度也百度不到详细题意
所以我在这里详细的讲解一下

题意:

输入n行,每行两个元素,表示一个区间,现在这n个区间每次只能在左端减1或者在右端加1,问如果这n个区间的长度和能被k整除,需要进行多少次变化?输出结果,
英文题目看不懂什么意思,废话一堆

AC

#include <bits/stdc++.h>
using namespace std;

int main()
{
    int n,k;
    scanf("%d%d",&n,&k);
    int sum=0;
    int l,r;
    while(n--)
    {
        scanf("%d%d",&l,&r);
        sum+=(r-l+1);//区间的长度就是区间内元素的个数
    }
    sum=(k-sum%k)%k;//这里多一次求余k的目的就是为了防止出现集合正好被整除的特殊情况!
    printf("%d",sum);
    return 0;
}

现在一直处于读题读不懂的状态,心累。。。

gpu工作状态诊断脚本 gpu工作和链路状态 立即下载

相关推荐

Mac-App-Uninstall-Offline-Fallback-Readiness-Auditor-v1.0-原创源码与文档.zip

本批资源均为独立编写的可运行 JavaScript 工程工具,包含完整源码、README、MIT License、原创与授权声明、可复现示例、自动化测试、离线 JSON/HTML/SVG 报告和真实运行截图。适合前端开发、AI 工程、自动化测试及技术研究人员用于本地预检、证据整理和二次开发。运行环境为 Node.js 18+,压缩包不含账号、密钥、Cookie、模型权重、品牌素材或第三方受限内容。

A. Polo the Penguin and Segments

time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Little penguin Polo adores integer segments, that is, pairs of i

无知的我 2426

WordPress-AI-Visibility-Offline-Fallback-Readiness-Auditor-v1.0-原创源码与文档.zip

本批资源均为独立编写的可运行 JavaScript 工程工具,包含完整源码、README、MIT License、原创与授权声明、可复现示例、自动化测试、离线 JSON/HTML/SVG 报告和真实运行截图。适合前端开发、AI 工程、自动化测试及技术研究人员用于本地预检、证据整理和二次开发。运行环境为 Node.js 18+,压缩包不含账号、密钥、Cookie、模型权重、品牌素材或第三方受限内容。

Codeforces-289a I Polo the Penguin and Segments

A. Polo the Penguin and Segments time limit per test 2 seconds memory limit per test 256 megabytes Little penguin Polo adores integer segments, that is, pairs of integers [l; r] (l ≤

JSure的代码库 3440

CodeForces 289A Polo the Penguin and Segments

 The value of a set of segments that consists of n segments [l1; r1], [l2; r2], ..., [ln; rn] is the number of integers x, such that there is integer j, for which the following inequality holds

Kim0403的博客 1056

Codeforces Round #177 (Div. 2) 题解

【前言】咦?现在怎么流行打CF了?于是当一帮大爷

阿蒋的专栏 1763

别再乱用宏定义和魔数了!用C语言位域让你的状态机代码更清晰可维护

本文探讨了如何利用C语言位域和联合体重构状态机代码,替代传统的宏定义和魔数,提升代码的可读性和可维护性。通过实际案例展示了位域在嵌入式开发和协议解析中的优势,包括调试效率提升和代码维护成本降低。

weixin_33722405的博客 397

CodeForces 289A

题意: 第一行给两个数n,k,之后给出n 行每行两个数字a,b 表示区间的边界,每次调整的时候只能调整a-1或者b+1,而且区间之间不可相交,要保证n 个区间长度的和可以被k整除的移动步数。如果不用移动就能被K整除就输出0. 输入: 2 3 1 2 3 4 3 7 1 2 3 3 4 7 输出: 2 0 分析: 如果区间长度之和对 k 有余,那么它的移

shao1996的博客 253

空调配电平面图.pdf.rar

空调配电平面图.pdf.rar

计算机房气体灭火系统图.dwg.rar

计算机房气体灭火系统图.dwg.rar

科技园区如何精准评估和招引优质科创项目?.docx

科易网基于40亿+科创知识图谱数据库,深度探索AI技术在技术转移、成果转化、技术经纪、知识产权、产业创新、科技招商等垂直领域的多样化应用场景,研究科技创新领域的AI+数智化解决方案,推动科技创新与产业创新智能化发展。

Email-Task-Assistant-State-Transition-Invariant-Checker-v1.0-原创源码与文档.zip

本批资源均为独立编写的可运行 JavaScript 工程工具,包含完整源码、README、MIT License、原创与授权声明、可复现示例、自动化测试、离线 JSON/HTML/SVG 报告和真实运行截图。适合前端开发、AI 工程、自动化测试及技术研究人员用于本地预检、证据整理和二次开发。运行环境为 Node.js 18+,压缩包不含账号、密钥、Cookie、模型权重、品牌素材或第三方受限内容。

Compact-Text-Model-Offline-Fallback-Readiness-Auditor-v1.0-原创源码与文档.zip

本批资源均为独立编写的可运行 JavaScript 工程工具,包含完整源码、README、MIT License、原创与授权声明、可复现示例、自动化测试、离线 JSON/HTML/SVG 报告和真实运行截图。适合前端开发、AI 工程、自动化测试及技术研究人员用于本地预检、证据整理和二次开发。运行环境为 Node.js 18+,压缩包不含账号、密钥、Cookie、模型权重、品牌素材或第三方受限内容。

某飞行出勤楼强、弱电竣工全套图纸.dwg.rar

某飞行出勤楼强、弱电竣工全套图纸.dwg.rar

某门诊楼电气图全套.dwg.rar

某门诊楼电气图全套.dwg.rar

某机房电气设计图.dwg.rar

某机房电气设计图.dwg.rar

滤波电容、去耦电容、旁路电容的作用.rar

滤波电容、去耦电容、旁路电容的作用.rar

技术转移机构如何提升科研成果转化效率?.docx

科易网基于40亿+科创知识图谱数据库,深度探索AI技术在技术转移、成果转化、技术经纪、知识产权、产业创新、科技招商等垂直领域的多样化应用场景,研究科技创新领域的AI+数智化解决方案,推动科技创新与产业创新智能化发展。

Eplan 图框 大小:A3

大小:A3 链接属性:位置代号,高层代号,公司名称,项目描述,页类型,图号 修订属性:修订名(出自修订信息跟踪) [1]~[3];修订索引(出自修订信息跟踪) [1]~[3];增补说明 [1]~[6];修订日期(出自修订信息跟踪) [1]~[3];修订创建者(出自修订信息跟踪) [1]~[3];

上一篇: CodeForces 288A Polo the Penguin and Strings
下一篇: UVa 1586 - Molar mass
Coder_Jeremy Wu
博客等级 码龄10年 12粉丝 53原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值