# Bzoj5102 [poi2018]prawnicy

## 构造乱搞

Posted by yjjr's blog on April 7, 2018

# 题目

## Sample Input

6 3
3 8
4 12
2 6
1 10
5 9
11 12


## Sample Output

4
1 2 4


# code

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<queue>
#include<map>
#define rep(i,a,b) for(register int i=a;i<=b;i++)
#define dep(i,a,b) for(register int i=a;i>=b;i--)
#define ll long long
#define mem(x,num) memset(x,num,sizeof x)
#define reg(x) for(int i=last[x];i;i=e[i].next)
using namespace std;
ll f=1,x=0;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
const int maxn=1e6+6;
int n,k,ans,mx,sum;
struct line{int l,r,id;}a[maxn];
priority_queue<int,vector<int>,greater<int> > q;
inline bool cmp(line a,line b){return a.l<b.l;}
int main()
{
sort(a+1,a+1+n,cmp);
rep(i,1,n){
if(q.size()<k)q.push(a[i].r);
else if(q.top()<a[i].r){q.pop();q.push(a[i].r);}
if(q.size()==k&&ans<q.top()-a[i].l){ans=q.top()-a[i].l;mx=a[i].l;}
}
printf("%d\n",ans);
if(!ans){rep(i,1,k)printf("%d ",i);return 0;}
rep(i,1,n){
if(sum>=k)break;
if(a[i].l<=mx&&mx+ans<=a[i].r){
sum++;
printf("%d ",a[i].id);
}
}
return 0;
}