#include #include #include #include #include #include #include #include #include #include #include using namespace std; int maxi, N, v[100009]; class RangeMinimumQuery { public: int N; void fix_val (int pos, int val) { dp[0][pos] = val; } void RunIt () { for (int i=2; i<=N; i++) lg[i] = lg[i >> 1] + 1; for (int i=1; (1< y) return x; return y; } }rmq; int main() { //freopen ("input", "r", stdin); //freopen ("output", "w", stdout); scanf ("%d", &N), rmq.N = N; for (int i=1; i<=N; i++) scanf ("%d", &v[i]), rmq.fix_val (i, v[i]); rmq.RunIt (); for (int i=1; i<=N; i++) for (int k=0; (1< N) dr = N; int curr = v[i] + rmq.Query (st, dr) - k; if ((i == 1 && k == 0) || curr > maxi) maxi = curr; } printf ("%d\n", maxi); return 0; }