Submission #74943590
Source Code Expand
#include <bits/stdc++.h>
using namespace std;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, m;
cin >> n >> m;
vector<int> d(n);
for(auto &x : d) cin >> x;
vector<int> bars(m);
for(auto &x : bars) cin >> x;
sort(bars.begin(), bars.end());
long long lo = 0, hi = 0;
for(int i = 0; i < n; i++){
long long D = d[i];
if(D > 0){
// Find rightmost p in [lo,hi] with no barricade in [p, p+D]
// Blocked positions: p in [b-D, b] for each barricade b
// Start from hi, jump left past blocked zones
long long p = hi;
long long new_hi = hi; // worst case: stay
while(p >= lo){
// Find first barricade >= p
auto it = lower_bound(bars.begin(), bars.end(), (int)p);
if(it == bars.end() || *it > p + D){
// p is unblocked!
new_hi = p + D;
break;
}
// barricade b = *it is in [p, p+D], blocks p
// Jump to b - D - 1
p = (long long)(*it) - D - 1;
}
hi = new_hi;
// lo unchanged (can always skip)
} else {
// D < 0, symmetric: find leftmost p in [lo,hi] with no barricade in [p+D, p]
// Blocked positions: p in [b, b-D] for each barricade b (note D<0, so -D>0)
// Start from lo, jump right past blocked zones
long long p = lo;
long long new_lo = lo; // worst case: stay
while(p <= hi){
// Find last barricade <= p
auto it = upper_bound(bars.begin(), bars.end(), (int)p);
if
Submission Info
| Submission Time | |
|---|---|
| Task | E - A Walk and Barricades |
| User | KAVIN_RAGAVINYAA |
| Language | C++23 (GCC 15.2.0) |
| Score | 0 |
| Code Size | 1862 Byte |
| Status | CE |
Compile Error
./Main.cpp: In function 'int main()':
./Main.cpp:54:19: error: expected '(' at end of input
54 | if
| ^
| (
./Main.cpp:54:19: error: expected '}' at end of input
./Main.cpp:51:27: note: to match this '{'
51 | while(p <= hi){
| ^
./Main.cpp:54:19: error: expected '}' at end of input
54 | if
| ^
./Main.cpp:44:16: note: to match this '{'
44 | } else {
| ^
./Main.cpp:49:23: warning: unused variable 'new_lo' [-Wunused-variable]
49 | long long new_lo = lo; // worst case: stay
| ^~~~~~
./Main.cpp:54:19: error: expected '}' at end of input
54 | if
| ^
./Main.cpp:20:31: note: to match this '{'
20 | for(int i = 0; i < n; i++){
| ^
./Main.cpp:54:19: error: expected '}' at end of input
54 | if
| ^
./Main.cpp:4:11: note: to match this '{'
4 | int main(){
| ^