제출 #863465

#제출 시각아이디문제언어결과실행 시간메모리
863465goodspeed0208Growing Vegetables is Fun 4 (JOI21_ho_t1)C++14
0 / 100
0 ms344 KiB
#include<iostream> #include<vector> #include<algorithm> #include<unordered_set> #define int long long #define MOD 1000000007 using namespace std; signed main() { int n; cin >> n; vector<int>v(n); int ans = 0; for (auto &i : v) cin >> i; int i = 1, j = n-2; int left = v[i-1] - v[i], right = v[j+1] - v[j]; while (i+1 < j) { while (left < 0 && i+1 < j) { i++; left= v[i-1] - v[i]; } while (right < 0 && i+1 < j) { j--; right = v[j+1] - v[j]; } if (left < 0 || right < 0) break; if ((left < right|| right < 0) && left >= 0) { ans += left + 1; //cout << left+1 << " " << i << " " << j << "\n"; right -= (left+1); left = -1; } else if (right >= 0){ ans += right + 1; //cout << right+1 << " " << i << " " << j << "\n"; left -= (right+1); right = -1; } } if (v[i] <= v[j]) { if (left >= 0) ans += min(left+1, v[j] - v[i] + 1); } //if (v[i] == v[j]) ans++; cout << ans /*<< " " << left << " " << right*/ <<"\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...