比赛 20091111 评测结果 ATAAAAAATT
题目名称 月度花费 最终得分 70
用户昵称 rottenwood 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2009-11-11 11:08:47
显示代码纯文本
program expense;
var
f:array[1..100000] of longint;
b:array[1..100000] of boolean;
i,j,k,m,n,max,c,ans:longint;
flag,cao:boolean;
procedure spring(num:longint);
 var i,j:longint; flag1,brother:boolean;
  begin
  c:=0;
  brother:=true;
  for i:=1 to n do if b[i] then begin brother:=false;break;end;
  if (num>m+1)and(not brother) then begin flag:=false;exit;end;
  if brother then begin
  if (num<=m+1) then flag:=true  else  flag:=false;
  exit;
  end;
  flag1:=true;
  i:=0;
  while (flag1)and(i<=n) do
   begin
   inc(i);
   if (b[i]) then begin c:=c+f[i];b[i]:=false; end;
   if c>ans then begin c:=c-f[i];b[i]:=true;flag1:=false;  end;
   end;
  spring(num+1);
  end;
function believe(x:longint):boolean;
var i,j:longint;
begin
flag:=true;
fillchar(b,sizeof(b),1);
 spring(1);
 if flag then believe:=true else believe:=false;
end;
procedure cnm(l,r:longint);
var i,j:longint;
 begin
 ans:=(l+r) div 2;
 if l=r then begin writeln(ans); close(output);halt;end;
 if believe(ans) then cao:=true else cao:=false;
 if (not cao)and(l<>r) then cnm(ans+1,r)
 else if (cao)and(l<>r) then cnm(l,ans);
 end;
begin
assign(input,'expense.in');reset(input);
assign(output,'expense.out');rewrite(output);
readln(n,m);
for i:=1 to n do
 begin
 readln(f[i]);
 max:=max+f[i];
 end;
cnm(0,max);
close(output);
end.