#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;
using ll = long long;
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define MAX(a, b) (((a) < (b)) ? (b) : (a))
int const nmax = 100000;
struct Picture{
int sz;
int value;
bool operator < (Picture const &a) const{
return sz < a.sz;
}
} v[1 + nmax];
int frame[1 + nmax];
int n, m;
int test(int target){
multiset<int> myset;
int result = 0, ptr = 1, currvalue = 0;
for(int i = m - target + 1; i <= m; i++){
while(ptr <= n && v[ptr].sz <= frame[i])
myset.insert(v[ptr++].value);
set<int>::iterator it = myset.lower_bound(currvalue);
if(it != myset.end()) {
currvalue = *it;
myset.erase(it);
} else
return 0;
}
return 1;
}
int binarysearch(int from, int to){
if(from < to){
int mid = (from + to + 1) / 2;
if(test(mid) == 1)
return binarysearch(mid, to);
else
return binarysearch(from, mid - 1);
} else
return from;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> m;
for(int i = 1;i <= n; i++)
cin >> v[i].sz >> v[i].value;
sort(v + 1, v + n + 1);
for(int i = 1;i <= m; i++)
cin >> frame[i];
sort(frame + 1, frame + m + 1);
cout << binarysearch(0, MIN(n, m));
return 0;
}
Compilation message
joi2019_ho_t2.cpp: In function 'int test(int)':
joi2019_ho_t2.cpp:25:7: warning: unused variable 'result' [-Wunused-variable]
int result = 0, ptr = 1, currvalue = 0;
^~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
388 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 |
420 KB |
Output is correct |
5 |
Correct |
2 ms |
292 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 |
296 KB |
Output is correct |
9 |
Correct |
2 ms |
292 KB |
Output is correct |
10 |
Correct |
2 ms |
396 KB |
Output is correct |
11 |
Correct |
2 ms |
384 KB |
Output is correct |
12 |
Correct |
2 ms |
296 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
420 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 |
424 KB |
Output is correct |
19 |
Correct |
2 ms |
292 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
388 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 |
420 KB |
Output is correct |
5 |
Correct |
2 ms |
292 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 |
296 KB |
Output is correct |
9 |
Correct |
2 ms |
292 KB |
Output is correct |
10 |
Correct |
2 ms |
396 KB |
Output is correct |
11 |
Correct |
2 ms |
384 KB |
Output is correct |
12 |
Correct |
2 ms |
296 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
420 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 |
424 KB |
Output is correct |
19 |
Correct |
2 ms |
292 KB |
Output is correct |
20 |
Correct |
3 ms |
376 KB |
Output is correct |
21 |
Correct |
4 ms |
380 KB |
Output is correct |
22 |
Correct |
2 ms |
376 KB |
Output is correct |
23 |
Correct |
3 ms |
376 KB |
Output is correct |
24 |
Correct |
4 ms |
376 KB |
Output is correct |
25 |
Correct |
4 ms |
428 KB |
Output is correct |
26 |
Correct |
4 ms |
376 KB |
Output is correct |
27 |
Correct |
2 ms |
348 KB |
Output is correct |
28 |
Correct |
3 ms |
436 KB |
Output is correct |
29 |
Correct |
4 ms |
504 KB |
Output is correct |
30 |
Correct |
1 ms |
376 KB |
Output is correct |
31 |
Correct |
4 ms |
536 KB |
Output is correct |
32 |
Correct |
2 ms |
376 KB |
Output is correct |
33 |
Correct |
2 ms |
396 KB |
Output is correct |
34 |
Correct |
4 ms |
408 KB |
Output is correct |
35 |
Correct |
2 ms |
376 KB |
Output is correct |
36 |
Correct |
4 ms |
376 KB |
Output is correct |
37 |
Correct |
4 ms |
408 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
388 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 |
420 KB |
Output is correct |
5 |
Correct |
2 ms |
292 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 |
296 KB |
Output is correct |
9 |
Correct |
2 ms |
292 KB |
Output is correct |
10 |
Correct |
2 ms |
396 KB |
Output is correct |
11 |
Correct |
2 ms |
384 KB |
Output is correct |
12 |
Correct |
2 ms |
296 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
420 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 |
424 KB |
Output is correct |
19 |
Correct |
2 ms |
292 KB |
Output is correct |
20 |
Correct |
3 ms |
376 KB |
Output is correct |
21 |
Correct |
4 ms |
380 KB |
Output is correct |
22 |
Correct |
2 ms |
376 KB |
Output is correct |
23 |
Correct |
3 ms |
376 KB |
Output is correct |
24 |
Correct |
4 ms |
376 KB |
Output is correct |
25 |
Correct |
4 ms |
428 KB |
Output is correct |
26 |
Correct |
4 ms |
376 KB |
Output is correct |
27 |
Correct |
2 ms |
348 KB |
Output is correct |
28 |
Correct |
3 ms |
436 KB |
Output is correct |
29 |
Correct |
4 ms |
504 KB |
Output is correct |
30 |
Correct |
1 ms |
376 KB |
Output is correct |
31 |
Correct |
4 ms |
536 KB |
Output is correct |
32 |
Correct |
2 ms |
376 KB |
Output is correct |
33 |
Correct |
2 ms |
396 KB |
Output is correct |
34 |
Correct |
4 ms |
408 KB |
Output is correct |
35 |
Correct |
2 ms |
376 KB |
Output is correct |
36 |
Correct |
4 ms |
376 KB |
Output is correct |
37 |
Correct |
4 ms |
408 KB |
Output is correct |
38 |
Correct |
260 ms |
6808 KB |
Output is correct |
39 |
Correct |
244 ms |
6812 KB |
Output is correct |
40 |
Correct |
536 ms |
7300 KB |
Output is correct |
41 |
Correct |
262 ms |
6804 KB |
Output is correct |
42 |
Correct |
61 ms |
4368 KB |
Output is correct |
43 |
Correct |
61 ms |
4340 KB |
Output is correct |
44 |
Correct |
447 ms |
6800 KB |
Output is correct |
45 |
Correct |
801 ms |
8408 KB |
Output is correct |
46 |
Correct |
699 ms |
8412 KB |
Output is correct |
47 |
Correct |
809 ms |
7548 KB |
Output is correct |
48 |
Correct |
801 ms |
7620 KB |
Output is correct |
49 |
Correct |
611 ms |
6688 KB |
Output is correct |
50 |
Correct |
483 ms |
6680 KB |
Output is correct |
51 |
Correct |
60 ms |
4344 KB |
Output is correct |
52 |
Correct |
60 ms |
4372 KB |
Output is correct |
53 |
Correct |
61 ms |
4344 KB |
Output is correct |
54 |
Correct |
989 ms |
9152 KB |
Output is correct |
55 |
Correct |
268 ms |
6908 KB |
Output is correct |
56 |
Correct |
69 ms |
5460 KB |
Output is correct |
57 |
Correct |
27 ms |
1748 KB |
Output is correct |
58 |
Correct |
300 ms |
7672 KB |
Output is correct |
59 |
Correct |
477 ms |
7804 KB |
Output is correct |
60 |
Correct |
24 ms |
1656 KB |
Output is correct |
61 |
Correct |
223 ms |
3960 KB |
Output is correct |
62 |
Correct |
709 ms |
6812 KB |
Output is correct |
63 |
Correct |
729 ms |
6776 KB |
Output is correct |
64 |
Correct |
794 ms |
6800 KB |
Output is correct |
65 |
Correct |
769 ms |
6816 KB |
Output is correct |
66 |
Correct |
754 ms |
6820 KB |
Output is correct |
67 |
Correct |
749 ms |
6808 KB |
Output is correct |
68 |
Correct |
727 ms |
6804 KB |
Output is correct |
69 |
Correct |
761 ms |
6820 KB |
Output is correct |
70 |
Correct |
758 ms |
6904 KB |
Output is correct |
71 |
Correct |
752 ms |
6904 KB |
Output is correct |
72 |
Correct |
645 ms |
6776 KB |
Output is correct |
73 |
Correct |
727 ms |
6904 KB |
Output is correct |