#include<bits/stdc++.h>
using namespace std;
#define INIT ios_base :: sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define mp make_pair
#define pb push_back
#define ft first
#define sc second
#define ll long long
#define pii pair<int, int>
#define count_bits __builtin_popcount
#define int ll
int t, n, m, s[100010], v[100010], c[100010];
pii pr[100010];
map<pii, vector<int>> h;
bool pos[100010];
multiset<pii> ms;
int32_t main(){
INIT
cin>>n>>m;
for(int i=1; i<=n; i++){
cin>>s[i]>>v[i];
ms.insert({v[i], s[i]});
pr[i]={s[i], v[i]};
}
sort(pr+1 , pr+1+n);
for(int i=1; i<=n; i++){
pos[i]=true;
h[pr[i] ].pb(i);
}
for(int i=1; i<=m ;i++){
cin>>c[i];
}
sort(c+1, c+1+m);
int pt=n;
int res=0;
for(int i=m; i>=1; i--){
while( (pt>=1) && ( (pos[pt]==false) || (pr[pt].ft>c[i]) ) ){
if(pos[pt]==false){
pt--; continue;
}
ms.erase(ms.find({pr[pt].sc, pr[pt].ft}) );
pt--;
}
if(pt>=1){
res++;
auto it=ms.end();
it--;
int loc=(h[ make_pair(it->sc, it->ft) ].back() ); h[ make_pair(it->sc, it->ft) ].pop_back(); pos[loc]=false;
ms.erase(it);
}
else{
break;
}
}
cout<<res;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
512 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
512 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
2 ms |
640 KB |
Output is correct |
21 |
Correct |
2 ms |
492 KB |
Output is correct |
22 |
Correct |
2 ms |
620 KB |
Output is correct |
23 |
Correct |
2 ms |
620 KB |
Output is correct |
24 |
Correct |
2 ms |
620 KB |
Output is correct |
25 |
Correct |
2 ms |
620 KB |
Output is correct |
26 |
Correct |
2 ms |
620 KB |
Output is correct |
27 |
Correct |
2 ms |
620 KB |
Output is correct |
28 |
Correct |
2 ms |
620 KB |
Output is correct |
29 |
Correct |
2 ms |
620 KB |
Output is correct |
30 |
Correct |
2 ms |
620 KB |
Output is correct |
31 |
Correct |
2 ms |
764 KB |
Output is correct |
32 |
Correct |
2 ms |
620 KB |
Output is correct |
33 |
Correct |
1 ms |
364 KB |
Output is correct |
34 |
Correct |
2 ms |
620 KB |
Output is correct |
35 |
Correct |
1 ms |
364 KB |
Output is correct |
36 |
Correct |
2 ms |
620 KB |
Output is correct |
37 |
Correct |
2 ms |
620 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
512 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
2 ms |
640 KB |
Output is correct |
21 |
Correct |
2 ms |
492 KB |
Output is correct |
22 |
Correct |
2 ms |
620 KB |
Output is correct |
23 |
Correct |
2 ms |
620 KB |
Output is correct |
24 |
Correct |
2 ms |
620 KB |
Output is correct |
25 |
Correct |
2 ms |
620 KB |
Output is correct |
26 |
Correct |
2 ms |
620 KB |
Output is correct |
27 |
Correct |
2 ms |
620 KB |
Output is correct |
28 |
Correct |
2 ms |
620 KB |
Output is correct |
29 |
Correct |
2 ms |
620 KB |
Output is correct |
30 |
Correct |
2 ms |
620 KB |
Output is correct |
31 |
Correct |
2 ms |
764 KB |
Output is correct |
32 |
Correct |
2 ms |
620 KB |
Output is correct |
33 |
Correct |
1 ms |
364 KB |
Output is correct |
34 |
Correct |
2 ms |
620 KB |
Output is correct |
35 |
Correct |
1 ms |
364 KB |
Output is correct |
36 |
Correct |
2 ms |
620 KB |
Output is correct |
37 |
Correct |
2 ms |
620 KB |
Output is correct |
38 |
Correct |
162 ms |
24428 KB |
Output is correct |
39 |
Correct |
104 ms |
14572 KB |
Output is correct |
40 |
Correct |
104 ms |
14700 KB |
Output is correct |
41 |
Correct |
146 ms |
21692 KB |
Output is correct |
42 |
Correct |
156 ms |
24428 KB |
Output is correct |
43 |
Correct |
170 ms |
24428 KB |
Output is correct |
44 |
Correct |
152 ms |
24632 KB |
Output is correct |
45 |
Correct |
205 ms |
24428 KB |
Output is correct |
46 |
Correct |
206 ms |
24556 KB |
Output is correct |
47 |
Correct |
261 ms |
23916 KB |
Output is correct |
48 |
Correct |
172 ms |
22764 KB |
Output is correct |
49 |
Correct |
137 ms |
17772 KB |
Output is correct |
50 |
Correct |
128 ms |
17772 KB |
Output is correct |
51 |
Correct |
192 ms |
24684 KB |
Output is correct |
52 |
Correct |
208 ms |
24428 KB |
Output is correct |
53 |
Correct |
183 ms |
24428 KB |
Output is correct |
54 |
Correct |
171 ms |
24428 KB |
Output is correct |
55 |
Correct |
169 ms |
24528 KB |
Output is correct |
56 |
Correct |
146 ms |
22892 KB |
Output is correct |
57 |
Correct |
20 ms |
2156 KB |
Output is correct |
58 |
Correct |
96 ms |
13036 KB |
Output is correct |
59 |
Correct |
195 ms |
22740 KB |
Output is correct |
60 |
Correct |
21 ms |
2156 KB |
Output is correct |
61 |
Correct |
76 ms |
9836 KB |
Output is correct |
62 |
Correct |
248 ms |
24428 KB |
Output is correct |
63 |
Correct |
223 ms |
24556 KB |
Output is correct |
64 |
Correct |
245 ms |
24556 KB |
Output is correct |
65 |
Correct |
227 ms |
24428 KB |
Output is correct |
66 |
Correct |
233 ms |
24428 KB |
Output is correct |
67 |
Correct |
241 ms |
24428 KB |
Output is correct |
68 |
Correct |
244 ms |
24428 KB |
Output is correct |
69 |
Correct |
224 ms |
24428 KB |
Output is correct |
70 |
Correct |
220 ms |
24428 KB |
Output is correct |
71 |
Correct |
262 ms |
24428 KB |
Output is correct |
72 |
Correct |
174 ms |
23788 KB |
Output is correct |
73 |
Correct |
168 ms |
24056 KB |
Output is correct |