Last active
December 29, 2015 20:21
-
-
Save knuu/c86dd50b02a913113bdc to your computer and use it in GitHub Desktop.
Codeforces Round #210 Div.2 D / Div.1 B - Levko and Array
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <bits/stdc++.h> | |
using namespace std; | |
typedef long long int ll; | |
int main() { | |
int N, K; cin >> N >> K; | |
vector<int> a(N); | |
for (int i = 0; i < N; i++) cin >> a[i]; | |
ll left = -1, right = 2*(int)1e9; | |
while (left + 1 < right) { | |
ll mid = (left + right) >> 1; | |
vector<int> dp(N, 1); | |
bool ok = false; | |
for (int i = 0; i < N; i++) { | |
for (int j = 0; j < i; j++) { | |
if (abs(a[i] - a[j]) <= mid * (ll)(i - j)) { | |
dp[i] = max(dp[i], dp[j] + 1); | |
} | |
} | |
if (N - dp[i] <= K) ok = true; | |
} | |
(ok ? right : left) = mid; | |
} | |
cout << right << endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment