573B - Bear and Blocks - CodeForces Solution


binary search data structures dp math *1600

Please click on ads to support us..

C++ Code:

#include <iostream>

const int MAX_N = 1e5 + 10;
const int INF = 1e9 + 10;

int n;

int value[MAX_N];
int minRight[MAX_N];
int minLeft[MAX_N];

int main() {

    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        scanf("%d", &value[i]);
    }

    minLeft[0] = 0 - 0;
    for (int i = 1; i <= n + 1; i++) {
        minLeft[i] = std::min(minLeft[i-1], value[i] - i);
    }
    
    minRight[n+1] = 0 + (n+1);
    for (int i = n; i >= 0; i--) {
        minRight[i] = std::min(minRight[i+1], value[i] + i);
    }

    int answer = 0;
    for (int i = 1; i <= n; i++) {
        int life = std::min(minLeft[i] + i, minRight[i] - i);
        answer = std::max(answer, life);
    }

    printf("%d\n", answer);

}


Comments

Submit
0 Comments
More Questions

876A - Trip For Meal
1326B - Maximums
1635C - Differential Sorting
961A - Tetris
1635B - Avoid Local Maximums
20A - BerOS file system
1637A - Sorting Parts
509A - Maximum in Table
1647C - Madoka and Childish Pranks
689B - Mike and Shortcuts
379B - New Year Present
1498A - GCD Sum
1277C - As Simple as One and Two
1301A - Three Strings
460A - Vasya and Socks
1624C - Division by Two and Permutation
1288A - Deadline
1617A - Forbidden Subsequence
914A - Perfect Squares
873D - Merge Sort
1251A - Broken Keyboard
463B - Caisa and Pylons
584A - Olesya and Rodion
799A - Carrot Cakes
1569B - Chess Tournament
1047B - Cover Points
1381B - Unmerge
1256A - Payment Without Change
908B - New Year and Buggy Bot
979A - Pizza Pizza Pizza