forked from sitz/UVa-Online-Judge
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path10020.cpp
57 lines (53 loc) · 817 Bytes
/
10020.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <bits/stdc++.h>
using namespace std;
struct interval
{
int l, r;
bool operator<(interval x) const
{
return l < x.l || (l == x.l && r < x.r);
}
} v[100048];
int idx[100048];
int main()
{
int c, k, l, m, r, t;
for (scanf("%d", &t); t-- && scanf("%d", &m) == 1;)
{
for (c = 0; scanf("%d %d", &v[c].l, &v[c].r) && (v[c].l || v[c].r); c++)
;
sort(v, v + c);
k = l = r = 0;
for (int i = 0; i < c && r < m; k++)
{
if (v[i].l > l)
{
i++;
}
for (; i < c && v[i].l <= l; ++i)
if (v[i].r >= r)
{
r = v[i].r;
idx[k] = i;
}
l = r;
}
if (r < m)
{
puts("0");
}
else
{
printf("%d\n", k);
for (int *p = idx; p < (idx + k); ++p)
{
printf("%d %d\n", v[*p].l, v[*p].r);
}
}
if (t)
{
putc(10, stdout);
}
}
return 0;
}