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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77 | #pragma comment(linker, "/STACK:10240000")
#include <bits/stdc++.h>
using namespace std;
#define X first
#define Y second
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(), (a).end()
#define fillchar(a, x) memset(a, x, sizeof(a))
typedef long long ll;
typedef pair<int, int> pii;
#ifndef ONLINE_JUDGE
namespace Debug {
void print(){cout<<endl;}template<typename T>
void print(const T t){cout<<t<<endl;}template<typename F,typename...R>
void print(const F f,const R...r){cout<<f<<", ";print(r...);}template<typename T>
void print(T*p, T*q){int d=p<q?:-;while(p!=q){cout<<*p<<", ";p+=d;}cout<<endl;}
}
#endif // ONLINE_JUDGE
template<typename T>bool umax(T&a, const T&b){return b<=a?false:(a=b,true);}
template<typename T>bool umin(T&a, const T&b){return b>=a?false:(a=b,true);}
/* -------------------------------------------------------------------------------- */
const int maxn = 1e5 + ;
multiset<int> s;
int n, m;
pii a[maxn], b[maxn];
void work() {
int ans = n - m;
s.clear();
int now = n - ;
for (int i = m - ; i >= ; i --) {
while (now >= && a[now].X >= b[i].X) s.insert(a[now --].Y);
if (!s.size()) {
puts("-1");
return ;
}
multiset<int>::iterator iter = s.upper_bound(b[i].Y);
if (iter == s.end()) s.erase(s.begin());
else {
ans ++;
s.erase(iter);
}
}
printf("%d\n", ans);
}
int main() {
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
#endif // ONLINE_JUDGE
int T, cas = ;
cin >> T;
while (T --) {
printf("Case #%d: ", ++ cas);
cin >> n >> m;
for (int i = ; i < n; i ++) {
scanf("%d%d", &a[i].X, &a[i].Y);
}
for (int i = ; i < m; i ++) {
scanf("%d%d", &b[i].Y, &b[i].X);
}
if (n < m) puts("-1");
else {
sort(a, a + n);
sort(b, b + m);
work();
}
}
return ;
}
|