#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int INF = 2e9 + 200;
int n[2], k, dist[2][600600];
pair<int, int> a[2][300300];
priority_queue<array<int, 3>, vector<array<int, 3>>, greater<array<int, 3>>> pq;
int getidx(int t, int p){
return upper_bound(a[t]+1, a[t]+n[t]+1, pair<int, int>(p, INF)) - a[t] - 1;
}
int calc(int t, int l, int r){
int li = getidx(t, l), ri = getidx(t, r);
return ri - li + (a[t][li].first <= l && l < a[t][li].second);
}
void push(int t, int c, int d){
if (dist[t][c] <= d) return;
dist[t][c] = d;
pq.push({d, t, c});
}
int main(){
scanf("%d %d %d", &n[0], &n[1], &k);
for (int i=0;i<2;i++){
for (int j=1;j<=n[i];j++){
scanf("%d %d", &a[i][j].first, &a[i][j].second);
}
sort(a[i]+1, a[i]+n[i]+1);
}
for (int i=0;i<2;i++) fill(dist[i], dist[i]+600600, INF);
if (a[0][1].first==0){
dist[0][1] = 0;
pq.push({0, 0, 1});
}
else{
dist[0][0] = 0;
pq.push({0, 0, 0});
}
int ans = 0;
while(!pq.empty()){
auto [d, t, c] = pq.top(); pq.pop();
if (d > dist[t][c]) continue;
// printf(" %d %d -> %d\n", t, c, d);
if (d > INF / 2) continue;
ans = max(ans, c);
int idx = getidx(t, d);
// printf(" idx = %d\n", idx);
if (idx+1 <= n[t]){
push(t, c+1, a[t][idx+1].first);
}
int e = d+k;
push(t^1, c+calc(t^1, d+k, e), e);
}
printf("%d\n", ans);
}
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:26:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
26 | scanf("%d %d %d", &n[0], &n[1], &k);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:29:9: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
29 | scanf("%d %d", &a[i][j].first, &a[i][j].second);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Incorrect |
2 ms |
4948 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Incorrect |
2 ms |
4948 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
4 ms |
4948 KB |
Output is correct |
4 |
Correct |
5 ms |
4948 KB |
Output is correct |
5 |
Correct |
4 ms |
5048 KB |
Output is correct |
6 |
Correct |
5 ms |
5060 KB |
Output is correct |
7 |
Correct |
5 ms |
4948 KB |
Output is correct |
8 |
Correct |
5 ms |
5076 KB |
Output is correct |
9 |
Correct |
4 ms |
5076 KB |
Output is correct |
10 |
Correct |
4 ms |
5076 KB |
Output is correct |
11 |
Correct |
3 ms |
4936 KB |
Output is correct |
12 |
Correct |
4 ms |
4948 KB |
Output is correct |
13 |
Correct |
3 ms |
4948 KB |
Output is correct |
14 |
Correct |
6 ms |
5076 KB |
Output is correct |
15 |
Correct |
5 ms |
5076 KB |
Output is correct |
16 |
Correct |
5 ms |
5036 KB |
Output is correct |
17 |
Correct |
4 ms |
5052 KB |
Output is correct |
18 |
Correct |
4 ms |
4928 KB |
Output is correct |
19 |
Correct |
4 ms |
5056 KB |
Output is correct |
20 |
Correct |
5 ms |
5056 KB |
Output is correct |
21 |
Correct |
5 ms |
5120 KB |
Output is correct |
22 |
Correct |
5 ms |
5076 KB |
Output is correct |
23 |
Correct |
4 ms |
4948 KB |
Output is correct |
24 |
Correct |
3 ms |
4932 KB |
Output is correct |
25 |
Correct |
4 ms |
5056 KB |
Output is correct |
26 |
Correct |
4 ms |
5104 KB |
Output is correct |
27 |
Correct |
3 ms |
4948 KB |
Output is correct |
28 |
Correct |
5 ms |
5076 KB |
Output is correct |
29 |
Correct |
5 ms |
5076 KB |
Output is correct |
30 |
Correct |
4 ms |
5056 KB |
Output is correct |
31 |
Correct |
4 ms |
5076 KB |
Output is correct |
32 |
Correct |
4 ms |
5056 KB |
Output is correct |
33 |
Correct |
2 ms |
4908 KB |
Output is correct |
34 |
Correct |
3 ms |
4948 KB |
Output is correct |
35 |
Correct |
3 ms |
4948 KB |
Output is correct |
36 |
Correct |
3 ms |
4948 KB |
Output is correct |
37 |
Correct |
3 ms |
4984 KB |
Output is correct |
38 |
Correct |
3 ms |
4916 KB |
Output is correct |
39 |
Correct |
3 ms |
4948 KB |
Output is correct |
40 |
Correct |
2 ms |
4916 KB |
Output is correct |
41 |
Correct |
3 ms |
4948 KB |
Output is correct |
42 |
Correct |
5 ms |
5076 KB |
Output is correct |
43 |
Correct |
5 ms |
5076 KB |
Output is correct |
44 |
Correct |
6 ms |
5076 KB |
Output is correct |
45 |
Correct |
5 ms |
5124 KB |
Output is correct |
46 |
Correct |
5 ms |
5076 KB |
Output is correct |
47 |
Correct |
3 ms |
4948 KB |
Output is correct |
48 |
Correct |
3 ms |
4948 KB |
Output is correct |
49 |
Correct |
3 ms |
4948 KB |
Output is correct |
50 |
Correct |
3 ms |
4932 KB |
Output is correct |
51 |
Correct |
3 ms |
5076 KB |
Output is correct |
52 |
Correct |
4 ms |
5076 KB |
Output is correct |
53 |
Correct |
3 ms |
5076 KB |
Output is correct |
54 |
Correct |
3 ms |
4948 KB |
Output is correct |
55 |
Correct |
4 ms |
5076 KB |
Output is correct |
56 |
Correct |
3 ms |
5076 KB |
Output is correct |
57 |
Correct |
3 ms |
5076 KB |
Output is correct |
58 |
Correct |
4 ms |
5076 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Incorrect |
2 ms |
4948 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |