#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
const double PI = 4 * atan(1);
#define sz(x) (int)(x).size()
#define ll long long
#define ld long double
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define pii pair <int, int>
#define vi vector<int>
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define vpi vector<pair<int, int>>
#define vpd vector<pair<double, double>>
#define pd pair<double, double>
#define f0r(i,a) for(int i=0;i<a;i++)
#define f1r(i,a,b) for(int i=a;i<b;i++)
#define trav(a, x) for (auto& a : x)
template<typename A, typename B> ostream& operator<<(ostream &cout, pair<A, B> const &p) { return cout << "(" << p.f << ", " << p.s << ")"; }
template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v) {
cout << "["; for(int i = 0; i < v.size(); i++) {if (i) cout << ", "; cout << v[i];} return cout << "]";
}
void fast_io(){
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
}
void io(string taskname){
string fin = taskname + ".in";
string fout = taskname + ".out";
const char* FIN = fin.c_str();
const char* FOUT = fout.c_str();
freopen(FIN, "r", stdin);
freopen(FOUT, "w", stdout);
fast_io();
}
const int MAX = 1e5 + 5;
vpi pic;
vi frame;
vi img;
int n, m;
int verify(int x){
if(x == 0) return 1;
//cout << x << endl;
vi use;
for(int i = m-x; i<m; i++){
use.eb(frame[i]);
}
int ptr = 0;
// cout << use << endl;
// cout <<img << endl;
f0r(i, n){
if(ptr == x) return 1;
if(img[i]<=use[ptr]){
// cout << img[i] << " " << use[ptr] << " " << ptr << " "<< i << endl;
ptr++;
}
}
// cout << ptr << " bad" << x << endl;
if(ptr >= x) return 1;
//cout << "here" << endl;
return 0;
}
int main(){
fast_io();
cin >> n >> m;
f0r(i, n){
int ai, bi;
cin >> ai >> bi;
pic.eb(mp(bi, ai));
}
f0r(i,m){
int ci;
cin >> ci;
frame.eb(ci);
}
sort(all(pic));
f0r(i, n) img.eb(pic[i].s);
sort(all(frame));
int l = 0;
int r = m;
while(abs(l-r)>1){
int mid = (l+r)/2;
int check = verify(mid);
if(check == 1){
l = mid;
}
else{
r = mid-1;
}
}
if(l>r) swap(l, r);
if(verify(r)) cout << r << endl;
else cout << l << endl;
return 0;
}
Compilation message
joi2019_ho_t2.cpp:1:0: warning: ignoring #pragma comment [-Wunknown-pragmas]
#pragma comment(linker, "/stack:200000000")
joi2019_ho_t2.cpp: In function 'void io(std::__cxx11::string)':
joi2019_ho_t2.cpp:52:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
freopen(FIN, "r", stdin);
~~~~~~~^~~~~~~~~~~~~~~~~
joi2019_ho_t2.cpp:53:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
freopen(FOUT, "w", stdout);
~~~~~~~^~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
256 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 |
504 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
3 ms |
376 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 |
2 ms |
376 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 |
380 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
256 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 |
504 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
3 ms |
376 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 |
2 ms |
376 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 |
380 KB |
Output is correct |
20 |
Correct |
3 ms |
376 KB |
Output is correct |
21 |
Correct |
3 ms |
376 KB |
Output is correct |
22 |
Correct |
3 ms |
376 KB |
Output is correct |
23 |
Correct |
3 ms |
376 KB |
Output is correct |
24 |
Correct |
3 ms |
376 KB |
Output is correct |
25 |
Correct |
3 ms |
380 KB |
Output is correct |
26 |
Correct |
3 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 |
3 ms |
376 KB |
Output is correct |
30 |
Correct |
3 ms |
376 KB |
Output is correct |
31 |
Correct |
3 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 |
3 ms |
376 KB |
Output is correct |
35 |
Correct |
2 ms |
376 KB |
Output is correct |
36 |
Correct |
3 ms |
376 KB |
Output is correct |
37 |
Correct |
3 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
256 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 |
504 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
3 ms |
376 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 |
2 ms |
376 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 |
380 KB |
Output is correct |
20 |
Correct |
3 ms |
376 KB |
Output is correct |
21 |
Correct |
3 ms |
376 KB |
Output is correct |
22 |
Correct |
3 ms |
376 KB |
Output is correct |
23 |
Correct |
3 ms |
376 KB |
Output is correct |
24 |
Correct |
3 ms |
376 KB |
Output is correct |
25 |
Correct |
3 ms |
380 KB |
Output is correct |
26 |
Correct |
3 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 |
3 ms |
376 KB |
Output is correct |
30 |
Correct |
3 ms |
376 KB |
Output is correct |
31 |
Correct |
3 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 |
3 ms |
376 KB |
Output is correct |
35 |
Correct |
2 ms |
376 KB |
Output is correct |
36 |
Correct |
3 ms |
376 KB |
Output is correct |
37 |
Correct |
3 ms |
376 KB |
Output is correct |
38 |
Correct |
69 ms |
5684 KB |
Output is correct |
39 |
Correct |
67 ms |
5744 KB |
Output is correct |
40 |
Correct |
63 ms |
5744 KB |
Output is correct |
41 |
Correct |
70 ms |
5740 KB |
Output is correct |
42 |
Correct |
66 ms |
5376 KB |
Output is correct |
43 |
Correct |
70 ms |
5360 KB |
Output is correct |
44 |
Correct |
68 ms |
5616 KB |
Output is correct |
45 |
Correct |
70 ms |
5724 KB |
Output is correct |
46 |
Correct |
68 ms |
5740 KB |
Output is correct |
47 |
Correct |
66 ms |
5232 KB |
Output is correct |
48 |
Correct |
77 ms |
5232 KB |
Output is correct |
49 |
Correct |
58 ms |
4724 KB |
Output is correct |
50 |
Correct |
59 ms |
4720 KB |
Output is correct |
51 |
Correct |
66 ms |
5356 KB |
Output is correct |
52 |
Correct |
66 ms |
5328 KB |
Output is correct |
53 |
Correct |
66 ms |
5364 KB |
Output is correct |
54 |
Correct |
62 ms |
5772 KB |
Output is correct |
55 |
Correct |
70 ms |
5796 KB |
Output is correct |
56 |
Correct |
42 ms |
3948 KB |
Output is correct |
57 |
Correct |
26 ms |
2164 KB |
Output is correct |
58 |
Correct |
41 ms |
3952 KB |
Output is correct |
59 |
Correct |
45 ms |
3952 KB |
Output is correct |
60 |
Correct |
26 ms |
2172 KB |
Output is correct |
61 |
Correct |
42 ms |
3304 KB |
Output is correct |
62 |
Correct |
74 ms |
5616 KB |
Output is correct |
63 |
Correct |
75 ms |
5588 KB |
Output is correct |
64 |
Correct |
75 ms |
5616 KB |
Output is correct |
65 |
Correct |
76 ms |
5612 KB |
Output is correct |
66 |
Correct |
78 ms |
5664 KB |
Output is correct |
67 |
Correct |
74 ms |
5748 KB |
Output is correct |
68 |
Correct |
75 ms |
5612 KB |
Output is correct |
69 |
Correct |
75 ms |
5616 KB |
Output is correct |
70 |
Correct |
76 ms |
5744 KB |
Output is correct |
71 |
Correct |
75 ms |
5740 KB |
Output is correct |
72 |
Correct |
70 ms |
5616 KB |
Output is correct |
73 |
Correct |
71 ms |
5616 KB |
Output is correct |