Advertisement
tien_noob

Hick - Code Solution

Jul 1st, 2021
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.05 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define TASK "TESTCODE"
  3. using namespace std;
  4. const int N = 1e2;
  5. int a[N + 1], b[N + 1], n;
  6. void read()
  7. {
  8.    cin >> n;
  9.    for (int i = 1; i <= n; ++ i)
  10.    {
  11.        cin >> a[i];
  12.    }
  13. }
  14. bool check(int k)
  15. {
  16.     b[1] = a[1] - k;
  17.     for (int i = 2; i <= n; ++ i)
  18.     {
  19.         if (a[i] + k <= b[i - 1])
  20.         {
  21.             return false;
  22.         }
  23.         b[i] = max(b[i - 1] + 1, a[i] - k);
  24.     }
  25.     return true;
  26. }
  27. void solve()
  28. {
  29.    int low = 0, high = 1e9;
  30.    while (low <= high)
  31.    {
  32.        int mid = (low + high)/2;
  33.        if (check(mid))
  34.        {
  35.            high = mid - 1;
  36.        }
  37.        else
  38.        {
  39.            low = mid + 1;
  40.        }
  41.    }
  42.    cout << low;
  43. }
  44. int main()
  45. {
  46.     ios_base::sync_with_stdio(false);
  47.     cin.tie(nullptr);
  48.     freopen(TASK".INP", "r", stdin);
  49.     freopen(TASK".OUT", "w", stdout);
  50.     int t = 1;
  51.     bool typetest = false;
  52.     if (typetest)
  53.     {
  54.         cin >> t;
  55.     }
  56.     for (int __ = 1; __ <= t; ++ __)
  57.     {
  58.         read();
  59.         solve();
  60.     }
  61. }
  62.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement