比赛 20101119 评测结果 AAAATTTTTT
题目名称 求和 最终得分 40
用户昵称 ybh 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2010-11-19 11:01:42
显示代码纯文本
{Sum NOIP模拟2010-11-19
 Author: yangbohua
 Time: 2010-11-19}

program suma;
var
  f:array[0..100001] of longint;
  a,n,k,p,i,j,temp,min:longint;

begin
  assign(input,'suma.in');
  reset(input);
  assign(output,'suma.out');
  rewrite(output);
  readln(n,k,p);
  f[0]:=0;
  for i:=1 to n do
  begin
    read(a);
    f[i]:=(f[i-1]+a) mod p;
  end;
  min:=maxlongint;
  for i:=1 to n do
    for j:=i to n do
    begin
      temp:=f[j]-f[i-1];
      if temp<0
        then temp:=temp+p;
      if (temp>=k) and (temp<min) then
      begin
        min:=temp;
        if min=k then
        begin
          writeln(k);
          close(input);
          close(output);
          halt;
        end;
      end;
    end;
  writeln(min);
  close(input);
  close(output);
end.