用户输出
4
系统信息
Exited with return code 0
编号 | 题目 | 状态 | 分数 | 总时间 | 内存 | 代码 / 答案文件 | 提交者 | 提交时间 |
---|---|---|---|---|---|---|---|---|
#237 | #1031. JM的特快列车 | Accepted | 100 | 312 ms | 744 K | C++ / 1.0 K | JM233333 | 2019-06-22 16:54:28 |
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long ll;
int binary_search(int left, int right);
bool check(int mindist);
const int MAX = 1e5 + 5;
int d[MAX];
int L;
int N, M;
int main() {
// freopen("test.txt", "r", stdin);
while (scanf("%d %d %d", &N, &M, &L) != EOF) {
// 输入
for (int i = 1; i <= N; i++) {
scanf("%d", &d[i]);
}
sort(d + 1, d + 1 + N);
d[0] = 0;
d[N + 1] = L;
// 求解
int res = binary_search(0, L);
// 输出
printf("%d\n", res);
}
return 0;
}
// 二分查找
int binary_search(int left, int right) {
int res = left;
while (left <= right) {
int mid = (left + right) / 2;
if (check(mid)) {
left = mid + 1;
res = mid;
} else {
right = mid - 1;
}
}
return res;
}
// check
bool check(int mindist) {
int cnt = 0;
int prv = 0;
for (int i = 1; i <= N + 1; i++) {
if (d[i] - d[prv] < mindist) {
cnt++;
} else {
prv = i;
}
}
return (cnt <= M);
}
95081 77335 568254347
160731933 121592942 545359032 42372661 94548234 31387055 297203963 120233938
<930969 bytes omitted>
用户输出
25967
系统信息
Exited with return code 0
93202 26371 640243133
544564116 20205828 399307350 600697625 98046473 248585032 150738566 19380659
<915056 bytes omitted>
用户输出
2706
系统信息
Exited with return code 0
98726 15172 4863256
4061736 2523417 2966284 1702310 1537399 4510660 4013440 4354876 2840737 4397394
<767088 bytes omitted>
用户输出
9
系统信息
Exited with return code 0
100000 99862 197697696
189350415 146517714 171890535 104293377 143894247 186136108 163590632 166302
<943029 bytes omitted>
用户输出
1420180
系统信息
Exited with return code 0
100000 142 25917879
25050015 18738442 17905039 7617439 1530367 10773344 8382003 14486136 11569183 2
<856866 bytes omitted>
用户输出
1
系统信息
Exited with return code 0
100000 0 409108430
185938952 21819912 310245988 320735736 37814393 158165858 368886326 407468247 43
<971434 bytes omitted>
用户输出
1
系统信息
Exited with return code 0
100000 100000 595536117
374138900 81845477 282044690 198472228 155427374 591666576 348669485 576466
<979298 bytes omitted>
用户输出
595536117
系统信息
Exited with return code 0
100000 69297 100001
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 3
<588817 bytes omitted>
用户输出
3
系统信息
Exited with return code 0
100000 85178 1000000000
2 4 6 8 9 10 12 14 16 18 19 20 22 23 24 25 27 29 31 32 33 35 36 37 39 41 42
<625941 bytes omitted>
用户输出
9
系统信息
Exited with return code 0
100000 14352 1000000000
1 2 3 5 7 8 10 12 13 15 16 18 20 21 23 25 26 27 29 31 32 33 35 37 38 40 41
<625955 bytes omitted>
用户输出
1
系统信息
Exited with return code 0
100000 99999 100031
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 3
<588817 bytes omitted>
用户输出
50015
系统信息
Exited with return code 0
100000 45195 916842072
4 5 9 11 12 13 14 17 21 25 27 30 34 36 40 42 45 46 49 50 54 57 61 62 64 65 6
<655452 bytes omitted>
用户输出
3
系统信息
Exited with return code 0
100000 2321 623818276
4 7 11 14 16 20 24 28 29 31 33 37 41 44 47 51 52 55 59 63 65 67 68 70 74 76 7
<655432 bytes omitted>
用户输出
1
系统信息
Exited with return code 0
100000 63443 223616492
2 4 6 9 10 14 16 20 23 25 28 29 33 36 38 40 41 42 44 45 49 51 54 58 59 61 64
<655623 bytes omitted>
用户输出
5
系统信息
Exited with return code 0