Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Make CSP great again
- //You're as beautiful as the day I lost you
- //New year, best wishes
- #include <bits/stdc++.h>
- #define TASK "TESTCODE"
- #define Log2(x) 31 - __builtin_clz(x)
- using namespace std;
- const int N = 1e5;
- int n, a[N + 3];
- void read()
- {
- cin >> n >> a[1] >> a[2];
- for (int i = 3; i <= n + 2; ++ i)
- {
- cin >> a[i];
- }
- }
- bool check(int k)
- {
- set<int> dp = {a[1]};
- set<int> :: iterator it;
- for (int i = 2; i < n + 2; ++ i)
- {
- if (dp.empty())
- {
- return false;
- }
- if (abs(a[i] - a[i + 1]) <= k)
- {
- dp.insert(a[i]);
- }
- while(!dp.empty() && a[i + 1] - *dp.begin() > k)
- {
- it = dp.begin();
- dp.erase(it);
- }
- while(!dp.empty() && *dp.rbegin() - a[i + 1] > k)
- {
- it = dp.end();
- --it;
- dp.erase(it);
- }
- }
- return !dp.empty();
- }
- void solve()
- {
- int low = abs(a[2] - a[1]), high = 1e9;
- while(low <= high)
- {
- int mid = (low + high)/2;
- if (check(mid))
- {
- high = mid - 1;
- }
- else
- {
- low = mid + 1;
- }
- }
- cout << low;
- }
- int main()
- {
- ios_base::sync_with_stdio(false);
- cin.tie(nullptr);
- if (fopen(TASK".INP", "r"))
- {
- freopen(TASK".INP", "r", stdin);
- //freopen(TASK".out", "w", stdout);
- }
- int t = 1;
- bool typetest = false;
- if (typetest)
- {
- cin >> t;
- }
- for (int __ = 1; __ <= t; ++ __)
- {
- //cout << "Case " << __ << ": ";
- read();
- solve();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement