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