标签:ati res out arm rate event long oca oid
5 3
1
2
8
4
9
3
#include<stdio.h>
#include<stdlib.h>
int N, C;
long long int loca[100000];
int compare(const void* a, const void* b) {
return *(long long int*)a - *(long long int*)b;
}
int cows(long long p) {
int cnt = 1;
long long last = loca[0];
for (int i = 1; i < N; ++i) {
if (loca[i] - last >= p) {
++cnt;
last = loca[i];
}
}
return cnt;
}
int main()
{
freopen("E:\\IDMdowanload\\in.txt", "r", stdin);
long long int maxdist = 0;
scanf("%d %d", &N, &C);
for (int i = 0; i < N; ++i) {
scanf("%lld", &loca[i]);
if (loca[i] > maxdist)maxdist = loca[i];
}
qsort(loca, N, sizeof(loca[0]), compare);
long long int l = 0, r = maxdist;
while (l < r) {
long long int mid = (l + r) / 2;
int p = cows(mid);
if (p < C)r = mid;
else l = mid + 1;
}
printf("%lld", l - 1);
return 0;
}
标签:ati res out arm rate event long oca oid
原文地址:https://www.cnblogs.com/orange-ga/p/12497437.html