将输入的时间转化成秒 然后排序 最后扫描一下就行了
#include<iostream>
#include<cstdio>
#include<set>
#include<string>
#include<string.h>
#include<cstring>
#include<vector>
#include<map>
#include<queue>
#include<stack>
#include<cctype>
#include<algorithm>
#include<sstream>
#include<utility>
#include<cmath>
#define mt(a) memset(a,0,sizeof (a))
#define fl(a,b,c) fill(a,b,c)
#define SWAP(a,b,t) (t=a,a=b,b=t)
#define inf 1000000
using namespace std;
typedef long long ll;
typedef struct node
{
int ti, id;
}node;
node tim[20000 + 20];
int who[20000 + 20];
int com(node x, node y)
{
return x.ti < y.ti;
}
int main()
{
int T;
cin >> T;
while (T--)
{
int n, l;
scanf("%d %d", &n, &l);
int h, m, s;
int k = 0;
for (int i = 0; i < n; i++)
{
scanf("%d:%d:%d", &h, &m, &s);
int t = h * 3600 + m * 60 + s;
tim[i].ti = t; tim[i].id = i + 1;
}
sort(tim, tim + n,com);
int ans = 0; int noneed = -1; int y = 0;
for (int i = 0; i < n; i++)
{
if (noneed < tim[i].ti){
noneed = tim[i].ti + l - 1; ans++;
who[y++] = tim[i].id;
}
}
printf("%d\n", ans);
sort(who, who + y);
for (int i = 0; i < y; i++)
{
if (i)printf(" ");
printf("%d", who[i]);
}
if (ans!=0)
printf("\n");
}
return 0;
}