# 【NOIP2016提高组复赛】蚯蚓

## Solution

x1$x1$被剪成p1q1p1=px1,q1=x1px1$p1和q1，p1=\lfloor px1\rfloor,q1=x1-\lfloor px1\rfloor$
x2$x2$被剪成p2q2p2=px2,q2=x2px2$p2和q2，p2=\lfloor px2\rfloor,q2=x2-\lfloor px2\rfloor$

p2q2$p2和q2$的大小关系同理。

a[0]预先存原序列的从大到小的排序。
a[1]存px的从大到小排序
a[2]存x-px的从大到小排序

## Code

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define fo(i,a,b) for(i=a;i<=b;i++)
using namespace std;
const int maxn=7100007;
typedef long long ll;
ll i,j,k,t,n,m,ans,p,q,u,v,da,x,y,tt;
ll a[3][maxn],l[3],r[3];
bool cmp(int x,int y){return x>y;}
int main(){
freopen("earthworm.in","r",stdin);
freopen("earthworm.out","w",stdout);
scanf("%d%d%d%d%d%d",&n,&m,&q,&u,&v,&tt);
fo(i,1,n+m)a[0][i]=a[1][i]=a[2][i]=-0x7fffffff;
fo(i,1,n)scanf("%lld",&a[0][i]);
sort(a[0]+1,a[0]+1+n,cmp);
l[0]=1,r[0]=n;l[1]=l[2]=1;r[1]=r[2]=0;
fo(i,1,m){
da=-0x7fffffff;
fo(j,0,2){
if(a[j][l[j]]>da)da=a[j][l[j]],k=j;
}
t=da+(i-1)*q;
l[k]++;
if(i%tt==0)printf("%lld ",t);
x=t*u/v;y=t-x;
a[1][++r[1]]=x-i*q;
a[2][++r[2]]=y-i*q;
}
printf("\n");
fo(i,1,n+m){
da=-0x7fffffff;
fo(j,0,2){
if(a[j][l[j]]>da)da=a[j][l[j]],k=j;
}
t=da+m*q;
l[k]++;
if(i%tt==0)printf("%lld ",t);
}
}