Files
cses/CSES - CSES Problem Set/Traffic_Lights.cpp
2024-06-09 00:49:48 +02:00

30 lines
704 B
C++

//
// Created by darian on 07.06.24.
//
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
ll x; cin >> x;
int n; cin >> n;
map<ll, int> distances;
distances[x] = 1;
set<pair<ll, ll>> lines = {{0, x}};
for (int i{}; i < n; i++) {
ll t; cin >> t;
auto it = lines.lower_bound({t, t});
--it;
auto p = *it;
lines.erase(p);
lines.insert({p.first, t});
lines.insert({t, p.second});
if (distances[p.second - p.first] == 1) distances.erase(p.second - p.first);
distances[t - p.first]++;
distances[p.second - t]++;
cout << (*distances.rbegin()).first << endl;
}
}