LL a[MAXN]; boolcheck(int v){ for (int i = 1; i <= N; i ++) a[i] = X[i] - 2ll * v * T * i; if (a[1] < a[N]) returnfalse; int l = K, r = K, ll = K, lr = K; for (int i = l; i >= 1; i --) if (a[i] >= a[ll]) ll = i; for (int i = r; i <= N; i ++) if (a[i] <= a[lr]) lr = i; while (l != ll || r != lr) { int pl, pr; bool suc = false; for (pl = l; pl > ll; ) { if (a[pl - 1] < a[r]) break; if (a[-- pl] >= a[l]) break; } if (pl < l && a[pl] >= a[l]) { l = pl; suc = true; } for (pr = r; pr < lr; ) { if (a[pr + 1] > a[l]) break; if (a[++ pr] <= a[r]) break; } if (pr > r && a[pr] <= a[r]) { r = pr; suc = true; } if (! suc) returnfalse; } l = 1, r = N; while (l != ll || r != lr) { int pl, pr; bool suc = false; for (pl = l; pl < ll; ) { if (a[pl + 1] < a[r]) break; if (a[++ pl] >= a[l]) break; } if (pl > l && a[pl] >= a[l]) { l = pl; suc = true; } for (pr = r; pr > lr; ) { if (a[pr - 1] > a[l]) break; if (a[-- pr] <= a[r]) break; } if (pr < r && a[pr] <= a[r]) { r = pr; suc = true; } if (! suc) returnfalse; } returntrue; }
inlineintgetnum(){ int num = 0; char ch = getchar (); while (! isdigit (ch)) ch = getchar (); while (isdigit (ch)) num = (num << 3) + (num << 1) + ch - '0', ch = getchar (); return num; }
intmain(){ N = getnum (), K = getnum (), T = getnum (); for (int i = 1; i <= N; i ++) X[i] = getnum (); int left = 0, right = INF, ans; while (left <= right) { int mid = (left + right) >> 1; if (check (mid)) { ans = mid; right = mid - 1; } else left = mid + 1; } printf ("%d\n", ans);