#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
const int MAXN = 1e5 + 10;
void speed()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
int n, m;
vector < pair < int , int > > g;
vector < int > frames;
void read()
{
cin >> n >> m;
int xx, yy;
for (int i = 1; i <= n; ++ i)
{
cin >> xx >> yy;
g.push_back(make_pair(yy, xx));
}
sort(g.begin(), g.end());
for (int i = 1; i <= m; ++ i)
{
cin >> xx;
frames.push_back(-xx);
}
sort(frames.begin(), frames.end());
}
bool check(int goal)
{
int x;
int sz = goal-1;
for (int i = 0; i < g.size(); ++ i)
{
x = g[i].second;
if(x <= -frames[sz])
{
sz --;
if(sz < 0)return true;
}
}
return (sz < 0);
}
void bin_search()
{
int l = 1, r = m, mid, ans = 0;
while(l <= r)
{
mid = (l + r)/2;
if(check(mid))
{
ans = mid;
l = mid + 1;
}
else r = mid - 1;
}
cout << ans << endl;
}
int main()
{
speed();
read();
bin_search();
return 0;
}
/**
10 10
978749728 144544247
765886828 382970504
724321206 775440108
793469869 329793955
744661733 757784475
737531928 772848949
880702330 298220471
886356598 234769581
756489712 541017091
976784156 205683907
498207927
462526472
688444509
591128229
744661733
421432475
299894333
737531928
39584784
724321206
10 10
44994472 57160841
127592536 57160841
60187289 57160841
224262980 801083909
297577794 801083909
521325580 801083909
802591211 801083909
333555245 57160841
362230938 57160841
52476098 57160841
465120061
652114335
652114335
465120061
467708607
874271777
467708607
467708607
874271777
465120061
*/
Compilation message
joi2019_ho_t2.cpp: In function 'bool check(int)':
joi2019_ho_t2.cpp:35:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
35 | for (int i = 0; i < g.size(); ++ i)
| ~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
320 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 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 |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
320 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 |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
320 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 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 |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
320 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
360 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
332 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
328 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
332 KB |
Output is correct |
31 |
Correct |
1 ms |
332 KB |
Output is correct |
32 |
Correct |
1 ms |
328 KB |
Output is correct |
33 |
Correct |
1 ms |
340 KB |
Output is correct |
34 |
Correct |
1 ms |
340 KB |
Output is correct |
35 |
Correct |
1 ms |
328 KB |
Output is correct |
36 |
Correct |
1 ms |
356 KB |
Output is correct |
37 |
Correct |
1 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 |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
320 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 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 |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
320 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
360 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
332 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
328 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
332 KB |
Output is correct |
31 |
Correct |
1 ms |
332 KB |
Output is correct |
32 |
Correct |
1 ms |
328 KB |
Output is correct |
33 |
Correct |
1 ms |
340 KB |
Output is correct |
34 |
Correct |
1 ms |
340 KB |
Output is correct |
35 |
Correct |
1 ms |
328 KB |
Output is correct |
36 |
Correct |
1 ms |
356 KB |
Output is correct |
37 |
Correct |
1 ms |
340 KB |
Output is correct |
38 |
Correct |
37 ms |
2136 KB |
Output is correct |
39 |
Correct |
35 ms |
2136 KB |
Output is correct |
40 |
Correct |
33 ms |
2072 KB |
Output is correct |
41 |
Correct |
37 ms |
2032 KB |
Output is correct |
42 |
Correct |
37 ms |
2032 KB |
Output is correct |
43 |
Correct |
37 ms |
2120 KB |
Output is correct |
44 |
Correct |
47 ms |
2028 KB |
Output is correct |
45 |
Correct |
37 ms |
2120 KB |
Output is correct |
46 |
Correct |
39 ms |
2132 KB |
Output is correct |
47 |
Correct |
38 ms |
2000 KB |
Output is correct |
48 |
Correct |
37 ms |
2004 KB |
Output is correct |
49 |
Correct |
30 ms |
1812 KB |
Output is correct |
50 |
Correct |
30 ms |
1856 KB |
Output is correct |
51 |
Correct |
36 ms |
2008 KB |
Output is correct |
52 |
Correct |
36 ms |
2008 KB |
Output is correct |
53 |
Correct |
37 ms |
2128 KB |
Output is correct |
54 |
Correct |
32 ms |
2060 KB |
Output is correct |
55 |
Correct |
37 ms |
2052 KB |
Output is correct |
56 |
Correct |
23 ms |
1500 KB |
Output is correct |
57 |
Correct |
15 ms |
1112 KB |
Output is correct |
58 |
Correct |
28 ms |
1580 KB |
Output is correct |
59 |
Correct |
23 ms |
1620 KB |
Output is correct |
60 |
Correct |
14 ms |
1092 KB |
Output is correct |
61 |
Correct |
23 ms |
1528 KB |
Output is correct |
62 |
Correct |
41 ms |
2072 KB |
Output is correct |
63 |
Correct |
41 ms |
2120 KB |
Output is correct |
64 |
Correct |
41 ms |
2116 KB |
Output is correct |
65 |
Correct |
43 ms |
2084 KB |
Output is correct |
66 |
Correct |
41 ms |
2100 KB |
Output is correct |
67 |
Correct |
42 ms |
2120 KB |
Output is correct |
68 |
Correct |
41 ms |
2060 KB |
Output is correct |
69 |
Correct |
42 ms |
2072 KB |
Output is correct |
70 |
Correct |
40 ms |
2136 KB |
Output is correct |
71 |
Correct |
42 ms |
2108 KB |
Output is correct |
72 |
Correct |
39 ms |
2060 KB |
Output is correct |
73 |
Correct |
39 ms |
2140 KB |
Output is correct |