River Hopscotch
Time Limit: 2000MS |
|
Memory Limit: 65536K |
Total Submissions: 8422 |
|
Accepted: 3620 |
Description
Every year the cows hold an event featuring a peculiar version of hopscotch that involves carefully jumping from rock to R Ock in a river. The excitement takes place in a long, straight river with a rock at the start and another rock at the end, L units away fr Om the start (1≤l≤1,000,000,000). Along the between the starting and ending Rocks, N (0≤n≤50,000) more rocks appear, each at an integral distanced I from the start (0 < Di < L).
To play the game, each cow in turn starts at the starting rock and tries to reach the finish at the ending rock, jumping O Nly from rock to rock. Of course, less agile cows never make it to the final rock, ending up instead in the river.
Farmer John is proud of he cows and watches this event each year. But as time goes by, he tires of watching the timid cows of the other farmers limp across the short distances between rock s placed too closely together. He plans to remove several rocks on order to increase the shortest distance a cow would have the to jump to reach the end. He knows he cannot remove the starting and ending rocks, but he calculates that he had enough resources to remove up to M Rocks (0≤m≤n).
FJ wants to know exactly how much he can increase the shortest distance *before* He starts removing the rocks. Help Farmer John determine the greatest possible shortest distance a cow have to jump after removing the optimal set of M R Ocks.
Input line 1:three space-separated integers:l, N, and M
Lines 2.. N+1:each line contains a single integer indicating what far some rock was away from the starting rock. No Rocks share the same position.
Output Line 1: A single integer which is the maximum of the shortest distance A cow have to jump after removing M rocks
Sample Input
5 2
2
17
Sample Output
4
To add a starting and ending point. Two stone titles are equivalent to n-m+1 stones, including the end stone, and the distance is greater than the two answers.
The wording is similar to the previous question
The AC code is as follows:
Created by Taosama on 2015-04-22//Copyright (c) Taosama.
All rights reserved. #include <algorithm> #include <cctype> #include <cmath> #include <cstdio> #include < cstdlib> #include <cstring> #include <iomanip> #include <iostream> #include <map> #include &
lt;queue> #include <string> #include <set> #include <vector> using namespace std;
const int INF = 0X3F3F3F3F;
const int MOD = 1e9 + 7;
const int N = 1e5 + 10;
int L, N, M, a[50005];
BOOL Check (int x) {int last = 0;
<=> Select n-m spacing >=x for (int i = 1; I <= n + 1-m; ++i) {int idx = last + 1;
while (idx <= n + 1 && a[idx]-a[last] < x) ++idx;
if (idx = = n + 2) return false;
last = idx;
} return true; } int main () {#ifdef LOCAL freopen ("In.txt", "R", stdin);//Freopen ("OUT.txt", "w", stdout); #endif Ios_base::sy
Nc_with_stdio (0);
CIN >> L >> n >> m; for (inti = 1; I <= N;
++i) Cin >> A[i];
Sort (A + 1, a + n + 1); A[0] = 0;
A[n + 1] = L;
int L = 0, R = l + 1;
while (L + 1 < r) {int mid = L + R >> 1;
if (check (mid)) L = mid;
else R = Mid;
} cout << l << ' \ n ';
return 0;
}