one unfinished
This commit is contained in:
30
CSES - CSES Problem Set/Traffic_Lights.cpp
Normal file
30
CSES - CSES Problem Set/Traffic_Lights.cpp
Normal file
@@ -0,0 +1,30 @@
|
||||
//
|
||||
// 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;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user