Codeforces Round #390 (Div. 2//754D. Fedor and coupons

【解题报告】Codeforces Round #390 (Div. 2) 简略的解题报告 阅读详情

D. Fedor and coupons
time limit per test
4 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

All our characters have hobbies. The same is true for Fedor. He enjoys shopping in the neighboring supermarket.

The goods in the supermarket have unique integer ids. Also, for every integer there is a product with id equal to this integer. Fedor has ndiscount coupons, the i-th of them can be used with products with ids ranging from li to ri, inclusive. Today Fedor wants to take exactly k coupons with him.

Fedor wants to choose the k coupons in such a way that the number of such products x that all coupons can be used with this product xis as large as possible (for better understanding, see examples). Fedor wants to save his time as well, so he asks you to choose coupons for him. Help Fedor!

Input

The first line contains two integers n and k (1 ≤ k ≤ n ≤ 3·105) — the number of coupons Fedor has, and the number of coupons he wants to choose.

Each of the next n lines contains two integers li and ri ( - 109 ≤ li ≤ ri ≤ 109) — the description of the i-th coupon. The coupons can be equal.

Output

In the first line print single integer — the maximum number of products with which all the chosen coupons can be used. The products with which at least one coupon cannot be used shouldn't be counted.

In the second line print k distinct integers p1, p2, ..., pk (1 ≤ pi ≤ n) — the ids of the coupons which Fedor should choose.

If there are multiple answers, print any of them.

Examples
input
4 2
1 100
40 70
120 130
125 180
output
31
1 2 
input
3 2
1 12
15 20
25 30
output
0
1 2 
input
5 2
1 10
5 15
14 50
30 70
99 100
output
21
3 4 
Note

In the first example if we take the first two coupons then all the products with ids in range [40, 70] can be bought with both coupons. There are 31 products in total.

In the second example, no product can be bought with two coupons, that is why the answer is 0. Fedor can choose any two coupons in this example.


先按左端点对这些区间排序,然后用优先队列找符合条件且最合适的右端点

这个题应该有很多种做法, 看完题后第一想法是二分,但想了半天不知道怎么check。。最后搜了题解看网上的二分是枚举左端点然后对右端点二分,还要用树状数组维护=。=

想不出来二分,有想过排序加优先队列,但感觉每次出队出最小元素不是最优解,后来想通了,举几个例子,画一画就好了,其实就是对于每个区间,找别的区间里找左端点符合条件的区间(符合条件是指左端点比我小,在我左边),再从这些区间里找最大的右端点,对左端点排完序后,符合条件的其实也就是我前面的那些区间,通过维护一个长度为k的优先队列,找到那个最大。

#include<stdio.h>
#include<algorithm>
#include<functional>
#include<queue>
using namespace std;
struct node
{
	int le,ri,num;
}nn[300005],ans;
struct cmp1
{
	bool operator()(int &a,int &b)
	{
		return a>b;
	}	
};
int cmp(node u,node v)
{
	return u.le<v.le;
}
int main()
{
	int n,k,i,maxx,t,j;
	priority_queue<int,vector<int>,cmp1>q;
	scanf("%d %d",&n,&k);
	for(i=0;i<n;i++)
	{
		scanf("%d %d",&nn[i].le,&nn[i].ri);
		nn[i].num=i+1;
	}
	sort(nn,nn+n,cmp);
	for(i=0;i<k;i++)
	{
		q.push(nn[i].ri);
	}
	maxx=q.top()-nn[k-1].le;
	ans.le=nn[k-1].le;
	ans.ri=q.top();
	for(i=k;i<n;i++)
	{
		q.pop();
		q.push(nn[i].ri);
		t=q.top()-nn[i].le;
		if(t>maxx)
		{
			maxx=t;
			ans.le=nn[i].le;
			ans.ri=q.top();
		}
	}
	//输出部分 
	if(maxx>=0)
	{
		printf("%d\n",maxx+1);
		for(i=0,j=0;i<n;i++)
		{
			if(j==k)
			break;
			if(nn[i].le<=ans.le&&nn[i].ri>=ans.ri)
			{
				printf("%d ",nn[i].num);
				j++;
			}
		}
		printf("\n");
	}
	else
	{
		printf("0\n");
		for(i=1;i<=k;i++)
		printf("%d ",i);
		printf("\n");
	}
	return 0;
}


PCB工艺-SI9000使用教程 本文介绍了阻抗计算工具SI9000的使用方法,重点讲解了微带线与带状线的区别、共面阻抗概念及参考面选择。通过USB差分走线实例,详细说明了如何选择计算模型、填写参数并确定线宽线距。文章还提供了层叠设计资料和工厂常规阻抗表格作为参考,建议制板时标注需控阻抗的线路供板厂调整。最后简单提及了嘉立创阻抗计算工具作为备选方案。 阅读详情

相关推荐

保姆级教程:手把手教你下载和配置Waymo自动驾驶数据集(附百度网盘链接)

本文提供了一份详细的Waymo自动驾驶数据集下载和配置指南,特别针对国内研究者优化了数据获取方案,包括百度网盘链接和Google Cloud CLI配置。文章还涵盖了环境配置、数据处理实战、可视化分析以及进阶技巧,帮助开发者高效利用这一业界黄金标准数据集进行自动驾驶研究。

weixin_42651281的博客 382

[cf] Codeforces Round #754 (Div. 2)

目录前言A.M. DeviationCODEB. Reverse SortCODEC - Dominant CharacterCODE 前言 没想到,只有过3题的水平,都可以上蓝 传送门 : A.M. Deviation 操作 : abc中任意选一个 让其中一个减一另一个加一 答案 : 使得最后答案 |a+c - 2*b| 最小 我们令 sum=a+csum = a+csum=a+c 会发现 选这两个数进行操作的话,最终对于sum来说值是不变的 因此我们 的ans=∣sum−2∗b∣ans = |sum -

qq_34364611的博客 898

Golang面试(一)莉莉丝游戏-Golang后端开发-中台部门

莉莉丝游戏-Golang后端开发-中台部门 开场白,双方自我介绍,对方介绍这个岗位情况,erlang语言,全部转向go。 聊项目,介绍IM架构以及使用Go写的服务简介 动态扩容相关问题:平常30万,现在100万,你们现在是如何应对的? 如果让你调整架构实现动态扩容,你会怎么做?回答了kafka,是一种,应该还要使用docker和k8s以及微服务框架等 如果使用kafka,你是如何确保消息有序?回答了redis,好像没回答到那个点 消息发送失败的问题,如何做到消息不丢?回答持久化存储、拉消息和ACK 发送失

xmcy001122的专栏 3903

Codeforces Round #754 (Div. 2)

A.A.M. Deviation 题目描述 ​ 给三个数,a1,a2,a3a_1,a_2,a_3a1​,a2​,a3​ 可以选择两个数ai,aj(i≠j)a_i,a_j(i\not=j)ai​,aj​(i​=j) 让ai−−,aj++a_i--,a_j++ai​−−,aj​++ 要求使得∣a1+a3−2×a2∣|a_1+a_3-2\times a_2|∣a1​+a3​−2×a2​∣最小 分析 ​ 我们发现选择操作a1,a2a_1,a_2a1​,a2​是没有意义的,只有选择a3a_3a3​和a1,a3

Code_Shark的博客 949

告别简陋行情!在Ubuntu24.04系统用Wine9.0跑同花顺远航版的全流程记录

本文详细记录了在Ubuntu 24.04系统上,通过Wine 9.0兼容层成功安装并流畅运行同花顺远航版的全过程。文章对比了该方案与官方简陋Linux原生版本的功能差异,重点解决了高分辨率屏幕下的字体与界面显示问题,并提供了关键配置调优与长期维护建议,为Linux用户提供了功能完备的专业金融行情解决方案。

weixin_29207533的博客 1082

Codeforces Round #754 (Div. 2) A、B、C题题解

A 题目说a1+a3=2*a2,所以我们可以判断a1,a2,a3的和是否可以分成三等份,如果可以,说明答案为0,如果不可以,说明答案为1(因为我可以挑选两个数,一个慢慢加,一个慢慢减,所以无论如何我的答案都不会超过1)。 #include<iostream> using namespace std; int main() { int t; cin>>t; while(t--) { int a,b,c; cin>>a>>b>>c;

Y12309的博客 908

保姆级教程:用Kalibr搞定Intel D435i三目(RGB+双目)相机联合标定,附完整ROSbag录制避坑指南

本文详细介绍了如何使用Kalibr工具对Intel D435i三目相机(RGB+双目)进行高精度联合标定,包括硬件准备、ROSbag录制技巧、Kalibr标定实战及结果验证。特别针对实际工程中的常见问题提供了解决方案,帮助开发者提升SLAM和三维重建等应用的精度。

weixin_42524762的博客 414

Codeforces Round #754 (Div. 2) 部分题解

文章目录前言SolutionsABCDObservation 1Observation 2SolutionEFCode 前言 神迹: 模拟赛切掉 A,C,E,但不会 B,D,F。 真就涉及到一丢丢构造和贪心就不会做呗,我是真的菜。 Solutions A 不难发现,每次操作可以将 a1+a3−2a2a_1+a_3-2a_2a1​+a3​−2a2​ 减小或增大 333。 若令 ppp 为初始时的 a1+a3−2a2a_1+a_3-2a_2a1​+a3​−2a2​,那么: 若 p≡0(mod3)p \equi

Cherrt的博客 666

【ARM CoreLink 系列 7 -- TZC-400控制器简介】

为了确保内存能够正确识别总线的信号控制位,新增一个TrustZone地址空间控制器(TrustZone Address Space Controller,TZASC)组件来实现对内存地址的安全扩展,将内存区域划分为安全内存区域和非安全内存区域,安全世界可以访问安全内存和非安全内存,而普通世界只能访问非安全内存,如下图所示:图 1-1内存区域的划分是在系统启动时通过配置 TZASC 组件(TZC-400/TZC-380)来实现的。TZC-400由和使能情况;安全访问权限;Base地址;

CodingCos的博客 1636

【PINN物理信息网络】基于PINN物理信息网络结合Wave 2D有限差分方法(python)

【PINN物理信息网络】基于PINN物理信息网络结合Wave 2D有限差分方法(python)

k8291121的博客 1821

Codeforces Round #390 (Div. 2) D. Fedor and coupons

原题网址:http://codeforces.com/contest/754/problem/D 大意是n个区间选k个,使得所有区间交集最大。 显然区间交的开始点肯定为一个左端点,按照左端点排序,维护两个堆,堆里记区间右端点,一开始先塞到大根堆里,若小根堆不满k个,就把大根堆里的压到小根堆里去。当小根堆满k个就可以统计答案。途中注意删除过期的点。换元素换位置写错了,还有标号标错了,比赛时WA

MintGreen 412

2026 企查查/天眼查:IP频率限制 + 验证码策略,企业工商数据采集实战

企业工商数据采集技术解析与解决方案 本文深度剖析了2026年企查查和天眼查平台的反爬机制与技术对抗方案。主要内容包括: 反爬机制分析: 采用JA4+ TLS指纹识别、极验v6验证码等多层防护 IP限制策略严格区分未登录/普通/VIP账号 精准识别并封禁数据中心IP 核心解决方案: 构建高可用住宅代理池,动态轮换真实用户IP 基于YOLOv8的验证码缺口识别技术(准确率99%) 分布式架构设计,支持千万级数据采集 多账号池管理与行为模拟技术 技术亮点: 动态住宅IP池实现1%以下封禁率 Playwright浏

专注于Python爬虫开发,分享爬虫技巧、项目实战与反爬经验,使用Scrapy、BeautifulSoup等工具,解决数据抓取难题。 1351

Codeforces Round #390 (Div. 2) D. Fedor and coupons(区间最大交集+优先队列)

http://codeforces.com/contest/754/problem/D 题意: 给定几组区间,找k组区间,使得它们的公共交集最大。 思路: 在k组区间中,它们的公共交集=k组区间中右端点最小值-k组区间中左端点最大值。如果我们要区间大,那我们应该尽量让左端点小,右端点大。 先对区间按照左端点排序,然后用优先队列处理。 将区间按照左端点从小到大的顺序一一进队列,只需...

weixin_30352191的博客 182

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

Probability and Statistics - 4th edition

Probability and Statistics - 4th edition

Codeforces Round #754 (Div. 2), problem: (D)

ps:写在飞书上的,对于不想看英文的同学很不友好,就先用中文说一说思路:首先题目要求我们对一个树上的结点进行重新relabel使 第一轮保证Eikooc胜利的情况他能够选择的结点最多,首先猜测有一种relabeling的方法使无论Eikooc无论选择哪一个结点,另一个人不能走第二步,这就要求对于所有的满足的结点j,k,它们之间不能直接相连,之后考虑将树的结点分为深度为奇数和偶数的两种,(因为同一深度的结点必定不能直接相连,而深度差为2的倍数的结点也必定不能直接相连)这样必有一种的个数小于等于n/2(n为树.

Ocean_Flow7的博客 461

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

Codeforces Round #754 (Div. 2) A B C

Codeforces Round #754 (Div. 2) A B C A. A.M. Deviation 思路:统计A,B,CA,B,CA,B,C三个数的数量的和mod3mod3mod3如果是奇数输出111否则输出000,为什么没有2呢???因为他求的ddd函数是绝对值所以abs(2−3)=1abs(2-3)=1abs(2−3)=1 参考代码 #include<bits/stdc++.h> using namespace std; #define snow ios::sync_wit

qq_53504307的博客 989

Outlook Express 6 (OE6) for Win7/Win8/Win10

英文版 Outlook Express6.0, 兼容Win7/Win10/WinXP,解压就可用。

Codeforces Round #754 (Div. 2)C. Dominant Character(区间dp||find函数||硬做)

C. Dominant Character time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Ashish has a string s of length n containing only characters ‘a’, ‘b’ and ‘c’. He wants to find the length of the smallest s

ycqmydarling的博客 890

Codeforces Round #382 (Div. 2)A到D题 A. Ostap and //B. Urbanization//C. Tennis Championship//D. Taxes

A. Ostap and Grasshopper time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output On the way to Rio de Janeiro Ostap

jerans的博客 1289

Gym - 101128C Canvas Painting 逆向思维

https://odzkskevi.qnssl.com/3699857ff0a17d77d1099699cdf4da13?v=1490503337 刚开始读错题意,以为是不变序列,就想着区间dp但数据量肯定会t,,,没想到什么优化方法就放下了,后来队员发现序列是可变的。。。。任意的。。。。。 想着先排序在布拉布拉布拉,一直都没有逆向思维想到哈夫曼。只怪数据结构没认真听啊。。。。 想到哈夫

jerans的博客 947

CodeForces - 361D Levko and Array二分加dp

D. Levko and Array time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Levko has an array that consists of inte

jerans的博客 840

Playrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2) C Fountains 乱搞

C. Fountains time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Arkady plays Gardenscapes a lot. Arkady wants

jerans的博客 810

codeforces 8VC Venture Cup 2017 - Elimination Round D PolandBall and Polygon

D. PolandBall and Polygon time limit per test 4 seconds memory limit per test 256 megabytes input standard input output standard output PolandBall has such a convex poly

jerans的博客 726

B. The Meeting Place Cannot Be Changed

B. The Meeting Place Cannot Be Changed time limit per test 5 seconds memory limit per test 256 megabytes input standard input output standard output The main road in Byt

jerans的博客 696

Codeforces Round #380 (Div. 2,Based on Technocup 2017 - Elimination Round 2)C - Road to Cine//

C. Road to Cinema time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Vasya is currently at a car rental service

jerans的博客 684

Beautiful numbers CodeForces - 55D 数位dp

D. Beautiful numbers time limit per test 4 seconds memory limit per test 256 megabytes input standard input output standard output Volodya is an odd boy and his taste is

jerans的博客 676
上一篇: qduoj 数组中出现最多的元素
下一篇: codeforces 8VC Venture Cup 2017 - Elimination Round D PolandBall and Polygon
jerans
博客等级 码龄10年 54粉丝 255原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值