-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path017-railway.cpp
More file actions
61 lines (60 loc) · 1.63 KB
/
Copy path017-railway.cpp
File metadata and controls
61 lines (60 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/*
* Railway [103149B]
* Problem: Gym/ICPC contest 103149 - problem B
* Verdict: ACCEPTED Solved: 2023-12-12
* Language: C++20 (GCC 11-64)
* Runtime: 1872 ms Memory: 800 KB
* Tags: n/a
* Author: BidoTeima
* Source: https://codeforces.com/gym/103149/submission/236929722
*/
#include <bits/stdc++.h>
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
using namespace std;
typedef long long ll;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int s,t,m,n;
cin>>s>>t>>m>>n;
int a[t],b[t],c[m],d[n],x;
for(int i = 0; i < t; i++) cin>>a[i];
for(int i = 0; i < t; i++) cin>>b[i];
for(int i = 0; i < m; i++) cin>>c[i];
for(int i = 0; i < n; i++) cin>>d[i], d[i] += s;
bool exist = 0;
for(int i = 0; i < t; i++){
int j = 0, k = 0;
// checking if exist there is train L->Z starting while a Z->L train is already inside
while(j < m && k < n){
x=d[k]-b[i];
if(c[j] + a[i] <= x && x < c[j] + b[i]){
exist = 1;
break;
}
else if(x < c[j] + a[i]){
++k;
}
else ++j;
}
j = 0, k = 0;
// same above but swap(Z->L, L->Z)
while(j < m && k < n){
x = c[j] + a[i];
if(d[k] - b[i] <= x && x < d[k] - a[i]){
exist = 1;
break;
}
else if(x < d[k] - b[i]){
++j;
}
else ++k;
}
if(exist)break;
}
cout<<(exist?"YES":"NO");
return 0;
}