Problem Description
The annual Games in frogs’ kingdom started again. The most famous game is the Ironfrog Triathlon. One test in the Ironfrog Triathlon is jumping. This project requires the frog athletes to jump over the river. The width of the river is L (1<= L <= 1000000000). There are n (0<= n <= 500000) stones lined up in a straight line from one side to the other side of the river. The frogs can only jump through the river, but they can land on the stones. If they fall into the river, they
are out. The frogs was asked to jump at most m (1<= m <= n+1) times. Now the frogs want to know if they want to jump across the river, at least what ability should they have. (That is the frog’s longest jump distance).

Input
The input contains several cases. The first line of each case contains three positive integer L, n, and m.
Then n lines follow. Each stands for the distance from the starting banks to the nth stone, two stone appear in one place is impossible.

Output
For each case, output a integer standing for the frog’s ability at least they should have.

Sample Input

6 1 2
2
25 3 3
11
2
18

Sample Output

4
11

Source
The 36th ACM/ICPC Asia Regional Dalian Site —— Online Contest


由于跳的次数<=m ,所以不妨二分跳的距离,看是否满足<=m ;
二分答案转为判定即可;

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<bitset>
#include<ctime>
#include<deque>
#include<stack>
#include<functional>
#include<sstream>
//#include<cctype>
//#pragma GCC optimize("O3")
using namespace std;
#define maxn 600005
#define inf 0x3f3f3f3f
#define INF 0x7fffffff
#define rdint(x) scanf("%d",&x)
#define rdllt(x) scanf("%lld",&x)
typedef long long  ll;
typedef unsigned long long ull;
typedef unsigned int U;
#define ms(x) memset((x),0,sizeof(x))
const int mod = 10000007;
#define Mod 20100403
#define sq(x) (x)*(x)
#define eps 1e-7
typedef pair<int, int> pii;
#define pi acos(-1.0)


inline int rd() {
	int x = 0;
	char c = getchar();
	bool f = false;
	while (!isdigit(c)) {
		if (c == '-') f = true;
		c = getchar();
	}
	while (isdigit(c)) {
		x = (x << 1) + (x << 3) + (c ^ 48);
		c = getchar();
	}
	return f ? -x : x;
}

ll gcd(ll a, ll b) {
	return b == 0 ? a : gcd(b, a%b);
}
ll sqr(ll x) { return x * x; }

int L, n, m;

int a[maxn];

bool check(int x) {
	int cnt = 0;
	int st = 0;

	for (int i = 1; i <= n; i++) {
		if (a[st] + x >= a[i] && a[st] + x < a[i + 1]) {
			cnt++; st = i;
		}
	}
	cnt++;
	if (cnt <= m)return true;
	else return false;
}


int main()
{
	//ios::sync_with_stdio(false);
	while (cin >> L >> n >> m) {
		for (int i = 1; i <= n; i++)rdint(a[i]);
		a[n + 1] = L;
		sort(a + 1, a + 2 + n);
		int maxx = -inf;
		for (int i = 1; i <= n + 1; i++) {
			maxx = max(maxx, a[i] - a[i - 1]);
		}
		int l = maxx, r = L;
		while (l <= r) {
			int mid = (l + r) / 2;
			if (check(mid))r = mid - 1;
			else l = mid + 1;
		}
		cout << l << endl;
	}
	return 0;
}

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<bitset>
#include<ctime>
#include<deque>
#include<stack>
#include<functional>
#include<sstream>
//#include<cctype>
//#pragma GCC optimize("O3")
using namespace std;
#define maxn 600005
#define inf 0x3f3f3f3f
#define INF 0x7fffffff
#define rdint(x) scanf("%d",&x)
#define rdllt(x) scanf("%lld",&x)
typedef long long  ll;
typedef unsigned long long ull;
typedef unsigned int U;
#define ms(x) memset((x),0,sizeof(x))
const int mod = 10000007;
#define Mod 20100403
#define sq(x) (x)*(x)
#define eps 1e-7
typedef pair<int, int> pii;
#define pi acos(-1.0)


inline int rd() {
	int x = 0;
	char c = getchar();
	bool f = false;
	while (!isdigit(c)) {
		if (c == '-') f = true;
		c = getchar();
	}
	while (isdigit(c)) {
		x = (x << 1) + (x << 3) + (c ^ 48);
		c = getchar();
	}
	return f ? -x : x;
}

ll gcd(ll a, ll b) {
	return b == 0 ? a : gcd(b, a%b);
}
ll sqr(ll x) { return x * x; }

int L, n, m;

int a[maxn];

bool check(int x) {
	int cnt = 0;
	int st = 0;

	for (int i = 1; i <= n; i++) {
		if (a[st] + x >= a[i] && a[st] + x < a[i + 1]) {
			cnt++; st = i;
		}
	}
	cnt++;
	if (cnt <= m)return true;
	else return false;
}


int main()
{
	//ios::sync_with_stdio(false);
	while (cin >> L >> n >> m) {
		for (int i = 1; i <= n; i++)rdint(a[i]);
		a[n + 1] = L;
		sort(a + 1, a + 2 + n);
		int maxx = -inf;
		for (int i = 1; i <= n + 1; i++) {
			maxx = max(maxx, a[i] - a[i - 1]);
		}
		int l = maxx, r = L;
		while (l <= r) {
			int mid = (l + r) / 2;
			if (check(mid))r = mid - 1;
			else l = mid + 1;
		}
		cout << l << endl;
	}
	return 0;
}