Advertisement
WayKillerZ

E - Breaking The Walls

May 17th, 2022
584
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <bits/stdc++.h>
  2.  
  3. #define int long long
  4. #define II pair<int, int>
  5. #define III pair<int, pair<int, int>>
  6. #define DI pair<double, int>
  7. #define fs first
  8. #define sc second
  9. #define mp(a, b) make_pair(a, b)
  10. #define LINF 9223372036854775807
  11. #define INF 2147483647
  12.  
  13. using namespace std;
  14.  
  15. int32_t main() {
  16.     ios_base::sync_with_stdio(false);
  17.     cin.tie(NULL);
  18.    
  19.     freopen("E.INP", "r", stdin);
  20.     freopen("E.OUT", "w", stdout);
  21.  
  22.     int n;
  23.     cin >> n;
  24.  
  25.     int arr[n+2];
  26.     int m = INF, m2 = INF;
  27.     for (int i = 1; i <= n; i++) {
  28.         cin >> arr[i];
  29.         if(arr[i] < m) {
  30.             m2 = m;
  31.             m = arr[i];
  32.         } else if(arr[i] < m2) {
  33.             m2 = arr[i];
  34.         }
  35.     }
  36.     int ans = (m+1)/2 + (m2+1)/2;
  37.     for(int i = 2; i <= n; i++) {
  38.         int f = max(arr[i], arr[i-1]);
  39.         int f2 = min(arr[i], arr[i-1]);
  40.  
  41.         if(f >= 2 * f2) ans = min(ans, (f+1)/2);
  42.         else ans = min(ans, (f + f2 + 2) / 3);
  43.     }
  44.  
  45.     for(int i = 1; i <= n-2; i++) {
  46.         ans = min(ans, (arr[i] + arr[i+2] + 1) / 2);
  47.         ans = min(ans, max(arr[i], arr[i+2]));
  48.     }
  49.  
  50.     cout << ans << endl;
  51.  
  52.     return 0;
  53. }
Advertisement
RAW Paste Data Copied
Advertisement