-
Notifications
You must be signed in to change notification settings - Fork 6
/
bm.pas
executable file
·105 lines (93 loc) · 1.99 KB
/
bm.pas
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
program magic;
const
maxn=600*600;
var
a,dis:array[0..660] of longint;
bian:array[0..30000]of record
x,y,z:longint;
end;
u:array[0..660]of boolean;
d,v,next:array[0..6000]of longint;
hp,num,n:longint;
procedure add(x,y,z:longint);
begin
inc(num);bian[num].x:=x;
bian[num].y:=y;
bian[num].z:=z;
end;
{procedure print;
var
x,i:longint;
begin
for x:=0 to n do
begin
writeln(x);
i:=head[x];
while i<>0 do
begin
write(v[i],':',d[i],';');
i:=next[i];
end;
writeln;
end;
writeln;
end; }
function can(cd:longint):boolean;
var
y,i,t,w,ci:longint; flag:boolean;
begin
num:=0;
for i:=1 to n do
if a[i]-hp>=0 then
begin
y:=(a[i]-hp)div 15;
add(i-1,y,-1)
end;
for i:=1 to n do
add(i,i-1,0);
for i:=cd to n do
add(i-cd,i,1);
fillchar(dis,sizeof(dis),$7f);
dis[0]:=0;
flag:=true;
ci:=0;
while flag do
begin
flag:=false;
inc(ci);
if ci>n+1 then break;
for i:=1 to num do
if dis[bian[i].y]>dis[bian[i].x]+bian[i].z then
begin
dis[bian[i].y]:=dis[bian[i].x]+bian[i].z;
flag:=true;
end;
end;
if ci>n+1 then exit(false) else exit(true);
end;
procedure init;
var
i,l,r,mid,x:longint;
begin
readln(n,hp);
for i:=1 to n do
begin
a[i]:=a[i-1];
read(x);
a[i]:=a[i]+x;
end;
l:=0;r:=n+1;
while l<r do
begin
mid:=(l+r)>>1;
if can(mid) then l:=mid+1 else r:=mid;
end;
if r=n+1 then writeln('No upper bound.')
else writeln(r-1)
end;
begin
assign(input,'magic.in');assign(output,'magic.out');
reset(input);rewrite(output);
init;
close(input);close(output);
end.