NOIP2016 蚯蚓

因为切的蚯蚓一定是越来越短的,所以开三个队列,每次在三个队首找一个最长的,切开后放到第二队和第三队的队尾,能保证三个队列都单调减。

var
  a:array[1..3,0..8000000] of longint;
  p,q:array[1..3] of longint;
  n,m,pl,u,v,t,i,j,cs,csj,cnt,plus:longint;
procedure swap(var a,b:longint);
  var t:longint;
  begin t:=a;a:=b;b:=t; end;
procedure sort(l,r:longint);
  var
    i,j,e:longint;
  begin
    i:=l;j:=r;e:=a[1][(l+r)>>1];
    repeat
      while a[1][i]>e do inc(i);
      while e>a[1][j] do dec(j);
      if not (i>j) then
        begin
          swap(a[1][i],a[1][j]);
          inc(i);dec(j);
        end;
    until i>j;
    if l<j then sort(l,j);
    if i<r then sort(i,r);
  end;
begin
  read(n,m,pl,u,v,t);
  p[1]:=1;p[2]:=1;p[3]:=1;
  q[1]:=n;q[2]:=0;q[3]:=0;
  for i:=1 to n do read(a[1][i]);
  sort(1,n);
  cnt:=0;plus:=0;
  for i:=1 to m do
    begin
      cs:=-1;
      for j:=1 to 3 do
        if ((p[j]<=q[j])and(a[j][p[j]]+plus>cs))
          then begin csj:=j;cs:=a[j][p[j]]+plus; end;
      inc(cnt);
      if (cnt=t) then
        begin
          write(cs,' ');
          cnt:=0;
        end;
      inc(p[csj]);
      inc(plus,pl);
      inc(q[2]);a[2][q[2]]:=int64(cs) * u div v - plus;
      inc(q[3]);a[3][q[3]]:=cs - (a[2][q[2]] + plus) - plus;
    end;
  writeln;
  cnt:=0;
  for i:=1 to n+m do
    begin
      cs:=-1;
      for j:=1 to 3 do
        if ((p[j]<=q[j])and(a[j][p[j]]+plus>cs))
          then begin csj:=j;cs:=a[j][p[j]]+plus; end;
      inc(p[csj]);
      inc(cnt);
      if (cnt=t) then
        begin
          write(cs,' ');
          cnt:=0;
        end;
    end;
  writeln;
end.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值