比赛 20091111 评测结果 ATAATETTTT
题目名称 月度花费 最终得分 30
用户昵称 Hamster 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2009-11-11 11:59:14
显示代码纯文本
program expense;
var
  i,x,j,t,n,m,max:longint;
  a:array[0..10001] of integer;

procedure fenzu(ii:longint);
var
  ss:longint;
begin
  t:=0;
  ss:=0;
  for i:=1 to n do
  begin
    if ss+a[i]<=ii then ss:=ss+a[i]
    else
	begin
	  inc(t);
	  ss:=a[i];
	end;
  end;
end;

procedure erfen(l1,l2:longint);
begin
  if l1=l2 then
  begin
    write(l1);
	close(input);
	close(output);
	halt;
  end;
  fenzu(((l1-l2) div 2+l2));
  if t<=m then
  erfen(((l1-l2) div 2+l2),l2)
  else
  erfen(l1,((l1-l2) div 2+l2));
end;

begin
  assign(input,'expense.in');
  assign(output,'expense.out');
  reset(input);
  rewrite(output);

  read(n,m);
  for i:=1 to n do
  begin
    readln(a[i]);
	max:=max+a[i];
    if a[i]>x then x:=a[i];
  end;
  erfen(max,x);

  close(input);
  close(output);
end.