#include <bits/stdc++.h>
using namespace std;
template<class A, class B>
ostream& operator<<(ostream& o, const pair<A, B>& p) {
return o << '(' << p.first << ", " << p.second << ')';
}
template<class T>
auto operator<<(ostream& o, const T& x) -> decltype(x.end(), o) {
o << '{';
bool first = true;
for (const auto& e : x) {
if (!first) {
o << ", ";
}
o << e;
first = false;
}
return o << '}';
}
#define DEBUG
#ifdef DEBUG
#define fastio()
#define debug(x...) cerr << "[" #x "]: ", [](auto... $) {((cerr << $ << "; "), ...); }(x), cerr << '\n'
#define check(x) if (!(x)) { cerr << "Check failed: " << #x << " in line " << __LINE__ << endl; exit(1); }
#else
#define fastio() ios_base::sync_with_stdio(0); cin.tie(0);
#define debug(...)
#define check(x)
#endif
typedef long long ll;
#define pi pair<int, int>
#define pl pair<ll, ll>
#define st first
#define nd second
#define vi vector<int>
#define vll vector<ll>
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
void solve() {
int n, m;
cin >> n >> m;
vector<pi>tab;
for(int i = 1; i <= n; i++) {
int a, b;
cin >> a >> b;
tab.pb({a, b});
}
sort(all(tab));
vi tab2;
for(int i = 1; i <= m; i++) {
int x;
cin >> x;
tab2.pb(x);
}
sort(all(tab2));
int l = 0;
int r = m;
while(l < r) {
int mid = (l + r + 1) / 2;
int pop = 0;
int j = 0;
multiset<int>akt;
int ans = 0;
for(int i = m - mid; i < m; i++) {
while(j < sz(tab) && tab[j].st <= tab2[i]) {
if(tab[j].nd >= pop) {
akt.insert(tab[j].nd);
}
j++;
}
if(akt.size()) {
ans++;
auto it = akt.find(*akt.begin());
pop = *akt.begin();
akt.erase(it);
}
}
if(ans == mid) {
l = mid;
}
else {
r = mid - 1;
}
}
cout << l << '\n';
}
int main() {
fastio();
int t;
//cin >> t;
t = 1;
while(t--) {
solve();
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
296 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
296 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
304 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
296 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
296 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
304 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
2 ms |
340 KB |
Output is correct |
21 |
Correct |
2 ms |
340 KB |
Output is correct |
22 |
Correct |
2 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
3 ms |
344 KB |
Output is correct |
25 |
Correct |
3 ms |
340 KB |
Output is correct |
26 |
Correct |
3 ms |
288 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
2 ms |
340 KB |
Output is correct |
30 |
Correct |
2 ms |
340 KB |
Output is correct |
31 |
Correct |
2 ms |
312 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
1 ms |
212 KB |
Output is correct |
34 |
Correct |
2 ms |
340 KB |
Output is correct |
35 |
Correct |
1 ms |
212 KB |
Output is correct |
36 |
Correct |
2 ms |
340 KB |
Output is correct |
37 |
Correct |
2 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
296 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
296 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
304 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
2 ms |
340 KB |
Output is correct |
21 |
Correct |
2 ms |
340 KB |
Output is correct |
22 |
Correct |
2 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
3 ms |
344 KB |
Output is correct |
25 |
Correct |
3 ms |
340 KB |
Output is correct |
26 |
Correct |
3 ms |
288 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
2 ms |
340 KB |
Output is correct |
30 |
Correct |
2 ms |
340 KB |
Output is correct |
31 |
Correct |
2 ms |
312 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
1 ms |
212 KB |
Output is correct |
34 |
Correct |
2 ms |
340 KB |
Output is correct |
35 |
Correct |
1 ms |
212 KB |
Output is correct |
36 |
Correct |
2 ms |
340 KB |
Output is correct |
37 |
Correct |
2 ms |
340 KB |
Output is correct |
38 |
Correct |
224 ms |
6684 KB |
Output is correct |
39 |
Correct |
225 ms |
6720 KB |
Output is correct |
40 |
Correct |
262 ms |
7108 KB |
Output is correct |
41 |
Correct |
235 ms |
6680 KB |
Output is correct |
42 |
Correct |
95 ms |
4796 KB |
Output is correct |
43 |
Correct |
97 ms |
4876 KB |
Output is correct |
44 |
Correct |
194 ms |
6680 KB |
Output is correct |
45 |
Correct |
469 ms |
8228 KB |
Output is correct |
46 |
Correct |
407 ms |
8304 KB |
Output is correct |
47 |
Correct |
387 ms |
7360 KB |
Output is correct |
48 |
Correct |
361 ms |
7444 KB |
Output is correct |
49 |
Correct |
329 ms |
6248 KB |
Output is correct |
50 |
Correct |
291 ms |
6260 KB |
Output is correct |
51 |
Correct |
96 ms |
4808 KB |
Output is correct |
52 |
Correct |
102 ms |
4896 KB |
Output is correct |
53 |
Correct |
96 ms |
4724 KB |
Output is correct |
54 |
Correct |
327 ms |
9088 KB |
Output is correct |
55 |
Correct |
259 ms |
6748 KB |
Output is correct |
56 |
Correct |
71 ms |
5328 KB |
Output is correct |
57 |
Correct |
34 ms |
1736 KB |
Output is correct |
58 |
Correct |
123 ms |
7664 KB |
Output is correct |
59 |
Correct |
247 ms |
7664 KB |
Output is correct |
60 |
Correct |
39 ms |
1716 KB |
Output is correct |
61 |
Correct |
138 ms |
3812 KB |
Output is correct |
62 |
Correct |
314 ms |
6628 KB |
Output is correct |
63 |
Correct |
305 ms |
6716 KB |
Output is correct |
64 |
Correct |
314 ms |
6596 KB |
Output is correct |
65 |
Correct |
347 ms |
6692 KB |
Output is correct |
66 |
Correct |
302 ms |
6688 KB |
Output is correct |
67 |
Correct |
316 ms |
6720 KB |
Output is correct |
68 |
Correct |
305 ms |
6636 KB |
Output is correct |
69 |
Correct |
326 ms |
6588 KB |
Output is correct |
70 |
Correct |
304 ms |
6716 KB |
Output is correct |
71 |
Correct |
293 ms |
6664 KB |
Output is correct |
72 |
Correct |
291 ms |
6616 KB |
Output is correct |
73 |
Correct |
260 ms |
6792 KB |
Output is correct |