#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define V vector
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << " is " << x << endl
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;
const int INF = 1e9 + 7, N = 100005;
pi a[N];
int c[N];
int n, m;
bool ok(int mid) {
int lst = -1;
multiset<int> s;
for(int i = m - mid, j = 0; i < m; i++) {
while(j < n && a[j].F <= c[i]) {
s.insert(a[j].S);
j++;
}
auto it = s.lower_bound(lst);
if(it == s.end()) return false;
lst = *it;
s.erase(it);
}
return true;
}
signed main()
{
IO_OP;
cin >> n >> m;
for(int i=0;i<n;i++)
cin >> a[i].F >> a[i].S;
sort(a, a+n);
for(int i=0;i<m;i++)
cin >> c[i];
sort(c, c+m);
int l = 0, r = m;
while(l <= r) {
int mid = (l + r) / 2;
if(ok(mid)) l = mid + 1;
else r = mid - 1;
}
cout << r << endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
380 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
0 ms |
380 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
19 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
380 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
0 ms |
380 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
19 |
Correct |
2 ms |
376 KB |
Output is correct |
20 |
Correct |
4 ms |
376 KB |
Output is correct |
21 |
Correct |
4 ms |
376 KB |
Output is correct |
22 |
Correct |
2 ms |
376 KB |
Output is correct |
23 |
Correct |
3 ms |
376 KB |
Output is correct |
24 |
Correct |
5 ms |
504 KB |
Output is correct |
25 |
Correct |
5 ms |
376 KB |
Output is correct |
26 |
Correct |
5 ms |
376 KB |
Output is correct |
27 |
Correct |
3 ms |
376 KB |
Output is correct |
28 |
Correct |
3 ms |
376 KB |
Output is correct |
29 |
Correct |
4 ms |
376 KB |
Output is correct |
30 |
Correct |
3 ms |
376 KB |
Output is correct |
31 |
Correct |
4 ms |
376 KB |
Output is correct |
32 |
Correct |
2 ms |
376 KB |
Output is correct |
33 |
Correct |
2 ms |
376 KB |
Output is correct |
34 |
Correct |
4 ms |
504 KB |
Output is correct |
35 |
Correct |
2 ms |
376 KB |
Output is correct |
36 |
Correct |
5 ms |
380 KB |
Output is correct |
37 |
Correct |
5 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
380 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
0 ms |
380 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
19 |
Correct |
2 ms |
376 KB |
Output is correct |
20 |
Correct |
4 ms |
376 KB |
Output is correct |
21 |
Correct |
4 ms |
376 KB |
Output is correct |
22 |
Correct |
2 ms |
376 KB |
Output is correct |
23 |
Correct |
3 ms |
376 KB |
Output is correct |
24 |
Correct |
5 ms |
504 KB |
Output is correct |
25 |
Correct |
5 ms |
376 KB |
Output is correct |
26 |
Correct |
5 ms |
376 KB |
Output is correct |
27 |
Correct |
3 ms |
376 KB |
Output is correct |
28 |
Correct |
3 ms |
376 KB |
Output is correct |
29 |
Correct |
4 ms |
376 KB |
Output is correct |
30 |
Correct |
3 ms |
376 KB |
Output is correct |
31 |
Correct |
4 ms |
376 KB |
Output is correct |
32 |
Correct |
2 ms |
376 KB |
Output is correct |
33 |
Correct |
2 ms |
376 KB |
Output is correct |
34 |
Correct |
4 ms |
504 KB |
Output is correct |
35 |
Correct |
2 ms |
376 KB |
Output is correct |
36 |
Correct |
5 ms |
380 KB |
Output is correct |
37 |
Correct |
5 ms |
376 KB |
Output is correct |
38 |
Correct |
258 ms |
6796 KB |
Output is correct |
39 |
Correct |
247 ms |
6888 KB |
Output is correct |
40 |
Correct |
285 ms |
7416 KB |
Output is correct |
41 |
Correct |
256 ms |
6800 KB |
Output is correct |
42 |
Correct |
63 ms |
4472 KB |
Output is correct |
43 |
Correct |
66 ms |
4428 KB |
Output is correct |
44 |
Correct |
448 ms |
6812 KB |
Output is correct |
45 |
Correct |
854 ms |
8424 KB |
Output is correct |
46 |
Correct |
699 ms |
8312 KB |
Output is correct |
47 |
Correct |
869 ms |
7544 KB |
Output is correct |
48 |
Correct |
812 ms |
7544 KB |
Output is correct |
49 |
Correct |
543 ms |
6412 KB |
Output is correct |
50 |
Correct |
458 ms |
6396 KB |
Output is correct |
51 |
Correct |
61 ms |
4344 KB |
Output is correct |
52 |
Correct |
62 ms |
4364 KB |
Output is correct |
53 |
Correct |
62 ms |
4344 KB |
Output is correct |
54 |
Correct |
454 ms |
9080 KB |
Output is correct |
55 |
Correct |
260 ms |
6776 KB |
Output is correct |
56 |
Correct |
69 ms |
5372 KB |
Output is correct |
57 |
Correct |
24 ms |
1656 KB |
Output is correct |
58 |
Correct |
153 ms |
7784 KB |
Output is correct |
59 |
Correct |
530 ms |
7900 KB |
Output is correct |
60 |
Correct |
26 ms |
1756 KB |
Output is correct |
61 |
Correct |
249 ms |
3912 KB |
Output is correct |
62 |
Correct |
913 ms |
6904 KB |
Output is correct |
63 |
Correct |
731 ms |
6908 KB |
Output is correct |
64 |
Correct |
802 ms |
6812 KB |
Output is correct |
65 |
Correct |
801 ms |
6776 KB |
Output is correct |
66 |
Correct |
786 ms |
6776 KB |
Output is correct |
67 |
Correct |
783 ms |
6940 KB |
Output is correct |
68 |
Correct |
787 ms |
6776 KB |
Output is correct |
69 |
Correct |
930 ms |
6904 KB |
Output is correct |
70 |
Correct |
805 ms |
6836 KB |
Output is correct |
71 |
Correct |
742 ms |
6844 KB |
Output is correct |
72 |
Correct |
705 ms |
6828 KB |
Output is correct |
73 |
Correct |
564 ms |
6916 KB |
Output is correct |