-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path158.cpp
More file actions
77 lines (70 loc) · 1.32 KB
/
158.cpp
File metadata and controls
77 lines (70 loc) · 1.32 KB
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
int main () {
int p[311];
int d[311];
int to[311];
int i, j, n, len, m;
scanf ("%d%d", &len, &n);
for (i = 1; i <= n; ++i)
scanf ("%d", &p[i]);
scanf ("%d", &m);
d[1] = 0;
for (i = 2; i <= m; ++i)
scanf ("%d", &d[i]);
double dlt = .0, ma = .0; double ans = .0;
for (i = 1; i <= n; ++i) {
double dis = 5000000000.0;
for (j = 1; j <= m; ++j) {
double t = fabs (p[i] - d[j]);
if (t < dis) {
dis = t;
to[i] = j;
}
}
ma += dis;
}
dlt += 0.5;
while (dlt + d[m] < len) {
double tmp = .0;
for (i = 1; i <= n; ++i) {
double dis = fabs (p[i] - dlt - d[to[i]]);
while (to[i] > 1) {
double t = fabs (p[i] - dlt - d[to[i] - 1]);
if (t < dis) {
dis = t;
to[i] --;
}
else break;
}
tmp += dis;
}
if (tmp > ma) {
ma = tmp;
ans = dlt;
}
dlt += 0.5;
}
dlt = len - d[m];
double tmp = .0;
for (i = 1; i <= n; ++i) {
double dis = fabs (p[i] - dlt - d[to[i]]);
while (to[i] > 1) {
double t = fabs (p[i] - dlt - d[to[i] - 1]);
if (t < dis) {
dis = t;
to[i] --;
}
else break;
}
tmp += dis;
}
if (tmp > ma) {
ma = tmp;
ans = dlt;
}
printf("%.1f %.1f", ans, ma);
return 0;
}