Files
python/TangDou/LuoGuBook/P3853.cpp
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

34 lines
1011 B
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 100010;
int a[N];
int L;//表示公路的长度
int n;//原有路标的数量
int K;//最多可增设的路标数量
bool check(int mid) {
//如果按空旷指数 mid进行安排那么需要安排几个路标
int t = 0; //需要增加的路标个数
for (int i = 1; i < n; i++)
if (a[i + 1] - a[i] > mid) {
t += (a[i + 1] - a[i]) / mid;
//如果余数为零,还是要减去一个滴~
if ((a[i + 1] - a[i]) % mid == 0) t--;
}
return t <= k;//如果现在的路标数量小于k,也还行?~
}
int main() {
cin >> L >> n >> k;
for (int i = 1; i <= n; i++) cin >> a[i];
int l = 0, r = L;
while (l < r) {
int mid = l + r >> 1;
if (check(mid)) r = mid; // 使得公路的“空旷指数”最小,向小了逼近r=mid
else l = mid + 1;
}
cout << l << endl;
return 0;
}