제출 #1320469

#제출 시각아이디문제언어결과실행 시간메모리
1320469resululubeyovGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++20
100 / 100
16 ms5056 KiB
#pragma GCC optimize("O3") #include <bits/stdc++.h> using namespace std; #define endl '\n' #define int long long #define F first #define S second #define pii pair<int, int> #define all(v) v.begin(), v.end() #define rall(v) v.rbegin(), v.rend() #define yes() cout << "YES" << endl #define no() cout << "NO" << endl #define gcd __gcd int lcm(int a, int b){ return a / gcd(a , b) * b; } bool isPalindrome(string s){ string x = s; reverse(x.begin(), x.end()); return x == s; } bool isPrime(int n){ if(n < 2) return false; if(n == 2) return true; if(n % 2 == 0) return false; for(int i = 3;i <= sqrt(n);i += 2){ if(n % i == 0) return false; } return true; } int dx[] = {1, -1, 0, 0}; int dy[] = {0, 0, 1, -1}; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); signed main() { //freopen("input.txt","r",stdin); //freopen("output.txt","w",stdout); ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n; cin >> n; int arr[n + 1]; for(int i = 1;i <= n;i++){ cin >> arr[i]; } int pref[n + 1], suf[n + 1]; pref[1] = 0; suf[n] = 0; for(int i = 2;i <= n;i++) pref[i] = pref[i - 1] + max(0LL, 1 - (arr[i] - arr[i - 1])); for(int i = n - 1;i >= 1;i--) suf[i] = suf[i + 1] + max(0LL, 1 - (arr[i] - arr[i + 1])); int ans = LLONG_MAX; for(int i = 1;i <= n;i++){ int x = max(pref[i], suf[i]); ans = min(ans, x); } cout << ans << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...