Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // OK BS http://contest.uni-smr.ac.ru/ru/problemset/6137/
- # include <iostream>
- # include <vector>
- using namespace std;
- bool check(vector<int32_t> &m, int32_t mid, int32_t n) {
- vector<int32_t> cur(n, mid);
- for (size_t i = 0; i < n; i++) {
- int32_t m_i = m[i];
- if (i > 0 && cur[i - 1] != 0) {
- m_i -= min(cur[i - 1], m_i);
- }
- int32_t x = min(cur[i], m_i);
- cur[i] -= x;
- m_i -= x;
- if (i < n - 1) {
- x = min(cur[i + 1], m_i);
- cur[i + 1] -= x;
- m_i -= x;
- }
- if (m_i != 0) {
- return false;
- }
- }
- return true;
- }
- int main() {
- int32_t n;
- cin >> n;
- vector<int32_t> m(n);
- for (size_t i = 0; i < n; i++) {
- cin >> m[i];
- }
- int32_t left = 0;
- int32_t right = 1000000;
- while (right - left > 1) {
- int32_t mid = (left + right) / 2;
- if (check(m, mid, n)) {
- right = mid;
- }
- else {
- left = mid;
- }
- }
- cout << right;
- return 0;
- }
Add Comment
Please, Sign In to add comment