| Task: | Freight Train |
| Sender: | Qianyun Guo |
| Submission time: | 2017-10-17 18:23:27 +0300 |
| Language: | C++ |
| Status: | READY |
| Result: | ACCEPTED |
| test | verdict | time | |
|---|---|---|---|
| #1 | ACCEPTED | 0.04 s | details |
| #2 | ACCEPTED | 0.34 s | details |
| #3 | ACCEPTED | 0.11 s | details |
| #4 | ACCEPTED | 0.03 s | details |
Code
#include<bits/stdc++.h>
using namespace std;
int T, n, w, l;
int d[10010];
bool ok(int x) {
int start = 1;
int idx = 0;
int s = 0;
while (start <= n) {
if (idx >= w || d[idx] - start > x){
s ++;
if (idx < w)
start = d[idx];
else start = n+1;
} else {
start += x;
s ++;
while (idx < w && d[idx] < start)
idx ++;
}
}
return s <= l;
}
int main() {
cin >> T;
while (T--) {
cin >> n >> w >> l;
for (int i = 0; i < w; i++)
cin >> d[i];
int l = 1;
int r = n;
while (l < r) {
int mid = (l + r) / 2;
if (ok(mid))
r = mid;
else l = mid+1;
}
cout << l << endl;
}
return 0;
}
Test details
Test 1
Verdict: ACCEPTED
| input |
|---|
| 6 6 2 2 1 2 8 3 3 1 4 7 ... |
| correct output |
|---|
| 2 3 2 3 3 ... |
| user output |
|---|
| 2 3 2 3 3 ... |
Test 2
Verdict: ACCEPTED
| input |
|---|
| 100 10000000 100 84 313750 383426 490027 515434 66... |
| correct output |
|---|
| 88356 110708 101990 246895 471637 ... |
| user output |
|---|
| 88356 110708 101990 246895 471637 ... |
Test 3
Verdict: ACCEPTED
| input |
|---|
| 20 840187717 3944 6178 39387 340773 645007 692489 945... |
| correct output |
|---|
| 40670 211835 1080572 139232 48241 ... |
| user output |
|---|
| 40670 211835 1080572 139232 48241 ... |
Test 4
Verdict: ACCEPTED
| input |
|---|
| 8 80 7 5 2 4 7 47 49 52 53 90 9 9 11 14 17 47 49 52 53 76 82 ... |
| correct output |
|---|
| 7 7 13 13 1 ... |
| user output |
|---|
| 7 7 13 13 1 ... |
