제출 #536140

#제출 시각아이디문제언어결과실행 시간메모리
536140ItamarGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++14
100 / 100
95 ms3164 KiB
#include <map> #include <iostream> using namespace std; #include <vector> #include <queue> #include <set> #include <algorithm> #define ll long long #define vi vector<int> #define vll vector<ll> #define pi pair<int,int> #define pl pair<ll,ll> int main() { vi dis; int n; cin >> n; int last; cin >> last; for (int i = 1; i < n; i++) { int a; cin >> a; dis.push_back(a - last); last = a; } ll s1 = 0; ll s2 = 0; for (int i = 0; i < n - 1; i++) { if (dis[i] <= 0) s1 -= dis[i]-1; } ll min = s1; for (int i = n - 2; i >= 0; i--) { if (dis[i] <= 0) s1 += dis[i]-1; else s2 += dis[i]+1; if (dis[i] == 0) s2++; if (min > max(s1, s2)) min = max(s1, s2); } cout << min; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...