记录编号 |
98827 |
评测结果 |
AAAAAAAAAAAAAAAAAAAAAAAAAAAAA |
题目名称 |
[HZOI 2014] 采姑娘的小蘑菇 |
最终得分 |
100 |
用户昵称 |
teacher |
是否通过 |
通过 |
代码语言 |
Pascal |
运行时间 |
1.816 s |
提交时间 |
2014-04-24 20:38:46 |
内存使用 |
2.28 MiB |
显示代码纯文本
var
n,m,i,j,s:longint;
a:array[1..100000] of int64;
w:array[0..100000,0..1] of int64;
x,y,ava,ans,y0,y1:int64;
procedure sort(l,r: longint);
var
i,j,x,y: longint;
begin
i:=l;
j:=r;
x:=a[(l+r) div 2];
repeat
while a[i]<x do
inc(i);
while x<a[j] do
dec(j);
if not(i>j) then
begin
y:=a[i];
a[i]:=a[j];
a[j]:=y;
inc(i);
j:=j-1;
end;
until i>j;
if l<j then
sort(l,j);
if i<r then
sort(i,r);
end;
procedure sort1(l,r: longint);
var
i,j,x: longint;
y:array[0..1] of int64;
begin
i:=l;
j:=r;
x:=w[(l+r) div 2,0];
repeat
while w[i,0]<x do
inc(i);
while x<w[j,0] do
dec(j);
if not(i>j) then
begin
y:=w[i];
w[i]:=w[j];
w[j]:=y;
inc(i);
j:=j-1;
end;
until i>j;
if l<j then
sort1(l,j);
if i<r then
sort1(i,r);
end;
begin
assign(input,'mushro.in'); reset(input);
assign(output,'mushro.out'); rewrite(output);
readln(n,m);
x:=0;
for i:=1 to n do read(a[i]);
w[0,0]:=1;
for i:=1 to m do begin
read(y);
j:=1;
while (j<=x) and (w[j,0]<>y) do inc(j);
if j<=x then inc(w[j,1]) else begin inc(x); w[x,0]:=y; w[x,1]:=1; end;
end;
sort(1,n);
sort1(1,x);
s:=1;
for i:=1 to x-1 do begin
if j>n then begin writeln(ans); halt; close(input); close(output); end;
y0:=w[i,0] div w[i-1,0];
y1:=w[i+1,0] div w[i,0];
ava:=w[i,1];
for j:=s to n do a[j]:=a[j] div y0;
for j:=s to n do begin
if a[j]=0 then begin inc(s); continue; end;
dec(ava,a[j] mod y1);
dec(a[j],a[j] mod y1);
if ava<=0 then break;
end;
if ava<=0 then begin inc(ans,w[i,1]); continue; end;
j:=s;
while (ava>0) and (j<=n) do begin
if a[j]>ava then begin dec(a[j],ava); break; end;
dec(ava,a[j]); inc(j);
end;
s:=j;
if s>n then begin writeln(ans+w[i,1]-ava); close(input); close(output); halt; end;
inc(ans,w[i,1]);
end;
ava:=0;
y0:=w[x,0] div w[x-1,0];
for i:=s to n do inc(ava,a[i] div y0);
if ava>w[x,1] then writeln(m) else
writeln(ans+ava);
close(input); close(output);
end.