Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define TASK "TESTCODE"
- using namespace std;
- const int N = 1e2;
- int a[N + 1], b[N + 1], n;
- void read()
- {
- cin >> n;
- for (int i = 1; i <= n; ++ i)
- {
- cin >> a[i];
- }
- }
- bool check(int k)
- {
- b[1] = a[1] - k;
- for (int i = 2; i <= n; ++ i)
- {
- if (a[i] + k <= b[i - 1])
- {
- return false;
- }
- b[i] = max(b[i - 1] + 1, a[i] - k);
- }
- return true;
- }
- void solve()
- {
- int low = 0, 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);
- freopen(TASK".INP", "r", stdin);
- freopen(TASK".OUT", "w", stdout);
- int t = 1;
- bool typetest = false;
- if (typetest)
- {
- cin >> t;
- }
- for (int __ = 1; __ <= t; ++ __)
- {
- read();
- solve();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement