The only difference between easy and hard versions is constraints.
You are given nn segments on the coordinate axis OX. Segments can intersect, lie inside each other and even coincide. The ii-th segment is [li;ri] (li≤ri) and it covers all integer points j such that li≤j≤ri.
The integer point is called bad if it is covered by strictly more than kk segments.
Your task is to remove the minimum number of segments so that there are no bad points at all.
Input
The first line of the input contains two integers nn and kk (1≤k≤n≤200) — the number of segments and the maximum number of segments by which each integer point can be covered.
The next nn lines contain segments. The ii-th line contains two integers lili and riri (1≤li≤ri≤200) — the endpoints of the ii-th segment.
Output
In the first line print one integer m (0≤m≤n) — the minimum number of segments you need to remove so that there are no bad points.
In the second line print mm distinct integers p1,p2,…,pm (1≤pi≤n) — indices of segments you remove in any order. If there are multiple answers, you can print any of them.
Examples
Input
7 2 11 11 9 11 7 8 8 9 7 8 9 11 7 9
Output
3 1 4 7
Input
5 1 29 30 30 30 29 29 28 30 30 30
Output
3 1 2 4
Input
6 1 2 3 3 3 2 3 2 2 2 3 2 3
Output
4 1 3 5 6
这一题是删除一个坏点如果一个点被覆盖超过k次,它就是坏点,此时删除最少的点,使这个点不是坏点。
这一题的难点就是排序删点,要删长的点,要删覆盖超过k次最多的点;
所以不好排序
此时可以选择 删一次排一次,更新一次,
这个题的格式和其他题不一样,要额外注意一下。
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
int book[1010],b[1000];
struct node
{
int x,y,z,s;
} a[10000];
int cmp(node l,node r)
{
return l.s>r.s;
}
int main()
{
int n,m;
scanf("%d %d",&n,&m);
memset(book,0,sizeof(book));
for(int i=0; i<n; i++)
{
scanf("%d %d",&a[i].x,&a[i].y);
a[i].z=i+1;
for(int j=a[i].x; j<=a[i].y; j++)
{
book[j]++;
}
}
for(int i=0; i<n; i++)
{
int ans=0;
for(int j=a[i].x; j<=a[i].y; j++)
if(book[j]>m)
ans+=book[j]-m;
a[i].s=ans;
}
sort(a,a+n,cmp);
int k=0,w=0;
while(a[k].s>0)
{
for(int i=a[k].x; i<=a[k].y; i++)
{
book[i]--;
}
b[w++]=a[k++].z;
for(int i=k;i<n;i++)
{
int sum=0;
for(int j=a[i].x;j<=a[i].y;j++)
if(book[j]>m)
sum+=book[j]-m;
a[i].s=sum;
}
sort(a+k,a+n,cmp);
}
sort(b,b+w);
printf("%d\n",w);
for(int i=0; i<w; i++)
printf("%d ",b[i]);
return 0;
}