讨论 / 水啊……………………………………………………………………
shit 2012-01-19 21:51:00
点我顶贴 收藏 删除
program hhh;

const

inf='maxmin.in';

ouf='maxmin.out';

var

d,f,g,p,v,n,i,j,min:longint;

box,s:array[0..30] of longint;

a:char;

q,w,e:string;

procedure init;

begin

assign(input,inf);

reset(input);

assign(output,ouf);

rewrite(output);

end;

procedure search(k,v:longint);

begin

if v<min then min:=v;

if v-(s[n]-s[k-1])>=min then exit;

if k<=n then begin

if v>=box[k] then search(k+1,v-box[k]);

search(k+1,v);

end;

end;

begin

init;

readln(v);

readln(n);

s[0]:=0;

for i:=1 to n do

begin

readln(box[i]);

s[i]:=s[i-1]+box[i];

end;

min:=v;

if s[n]<=v then min:=v-s[n]

else search(1,v);

writeln(min);

close(input);

close(output);

end.

查看更多回复
提交回复