比赛 |
20101119 |
评测结果 |
AATTTTTTTT |
题目名称 |
求和 |
最终得分 |
20 |
用户昵称 |
itachi |
运行时间 |
0.000 s |
代码语言 |
Pascal |
内存使用 |
0.00 MiB |
提交时间 |
2010-11-19 09:57:26 |
显示代码纯文本
program t3(input,output);
var
s:array[1..2,1..100000]of longint;
data:array[1..100000] of longint;
n,k,p,i,j,ans,step:longint;
begin
ans:=maxint;
assign(input,'suma.in');
reset(input);
assign(output,'suma.out');
rewrite(output);
readln(n,k,p);
for i:= 1 to n do
begin
readln(s[1,i]);
s[1,i]:=s[1,i] mod p;
data[i]:=s[1,i];
if (s[1,i]<ans)and (s[1,i]>=k) then ans:=s[1,i];
if ans=k then
begin
writeln(k);
close(input);
close(output);
exit;
end;
end;
step:=2;
repeat
case step mod 2 of
1:
begin
for i:=1 to n-step+1 do
begin
s[1,i]:=(s[2,i]+data[i+step-1] ) mod p;
if (s[1,i]<ans)and (s[1,i]>=k) then ans:=s[1,i];
if ans=k then
begin
writeln(k);
close(input);
close(output);
exit;
end;
end;
end;
0:begin
for i:=1 to n-step+1 do
begin
s[2,i]:=(s[1,i]+data[i+step-1]) mod p;
if (s[2,i]<ans)and (s[2,i]>=k) then ans:=s[2,i];
if ans=k then
begin
writeln(k);
close(input);
close(output);
exit;
end;
end;
end;
end;
inc(step);
until step=n;
writeln(ans);
close(input);
close(output);
end.