2个多小时,弱智了。。(连A都做不对,就不要做D了(迷))
#include<bits/stdc++.h>
#define lowbit(x) x&(-x)
#define LL long long
#define N 100005
#define M 1000005
#define mod 2147483648LL
#define inf 0x7ffffffff
using namespace std;
inline int ra()
{
int x=,f=; char ch=getchar();
while (ch<'' || ch>''){if (ch=='-') f=-; ch=getchar();}
while (ch>='' && ch<=''){x=x*+ch-''; ch=getchar();}
return x*f;
}
int n,k;
struct node{
int x,y,id;
}a[N<<];
bool cmp(node a, node b)
{
if (a.x==b.x) return a.y<b.y;
return a.x<b.x;
}
int ans,cnt;
int b[N<<],L,R;
set<pair<int , int > > q;
set<pair<int , int > >:: iterator it;
int main()
{
n=ra(); k=ra();
for (int i=; i<=n; i++)
a[i].x=ra(),a[i].y=ra(),a[i].id=i;
sort(a+,a+n+,cmp);
if (n==)//zz
{
cout<<a[].y-a[].x+<<endl;
cout<<"";
return ;
}
// for (int i=1; i<=n; i++)
// printf("%d %d %d\n",a[i].x,a[i].y,a[i].id);
q.insert(make_pair(a[].y,a[].id));
for (int i=; i<=n; i++)
{
pair<int , int > tmp,qwq;
tmp=*q.begin();
while (a[i].x>tmp.first && !q.empty())
{
q.erase(tmp);
tmp=*q.begin();
}
q.insert(make_pair(a[i].y,a[i].id));
if (q.size()>=k)
{
tmp=*q.begin();
if (ans<tmp.first-a[i].x+)
{
cnt=;
ans=tmp.first-a[i].x+;
L=a[i].x;
R=tmp.first;
}
q.erase(tmp); //这里比较有意思,这是最小的,只要记录的最小的是没有用了的,再加着反而会让结果变小
}
}
cout<<ans<<endl;
if (ans==)
{
for (int i=; i<=k; i++) cout<<i<<" ";
}
else
{
//cout<<L<<" "<<R<<endl;
for (int i=; i<=n; i++)
if (L>=a[i].x && R<=a[i].y && k) //tmd还能这么输出,真是尴尬啊、、、
cout<<a[i].id<<" ",k--;
}
return ;
}
//%%%%%%%%%%%%%%%%cf有数据就是好,面相数据编程233