传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=4721
先切出来的长的那段不会短于后切出来的长的(短的同样也成立)
所以每次被切的时候把长的扔进一个数组,短的扔进一个数组。这样数组就是有序的了。
然后每次从三个数组头找最大的切就好了。
输出格式:行末无空格,第二行无回车
#include<stdio.h>
#include<algorithm>
#include<iostream>
#define Void inline void
#define cint const int &
#define cbool const bool &
#define N 7100005
using namespace std;
typedef long long ll;
int ha,ta,hb,tb,hc,tc,a[N],b[N],c[N],tm,opt[N],Ta[N],Tb[N],Tc[N],n,m,q,u,v,t,ed,st=1;
inline int cal(cint p)
{
if (p==1) return ha<ta?a[ha+1]+q*(tm-Ta[ha+1]):-1;
if (p==2) return hb<tb?b[hb+1]+q*(tm-Tb[hb+1]):-1;
if (p==3) return hc<tc?c[hc+1]+q*(tm-Tc[hc+1]):-1;
}
Void PlanB(cint k,cbool f)
{
int g=cal(k),p1=(ll)g*u/v,p2=g-p1;
if (f) opt[++ed]=g;
if (p1<p2) swap(p1,p2);
b[++tb]=p1;Tb[tb]=tm+1;
c[++tc]=p2;Tc[tc]=tm+1;
}
Void pf(cint k,cbool f){if (f) opt[++ed]=cal(k);}
Void solve(cbool f,cbool op)
{
int k1=cal(1),k2=cal(2),k3=cal(3);
if (k2<=k1 && k3<=k1) (op?PlanB(1,f):pf(1,f)),ha++;
else if (k3<=k2) (op?PlanB(2,f):pf(2,f)),hb++;
else (op?PlanB(3,f):pf(3,f)),hc++;
if (f) st=0;
}
Void out()
{
for (int i=1;i<ed;i++) printf("%d ",opt[i]);
if (ed) printf("%d",opt[ed]);
ed=0;st=1;
}
int main()
{
scanf("%d%d%d%d%d%d",&n,&m,&q,&u,&v,&t);
for (int i=1;i<=n;i++) scanf("%d",a+i);ta=n;
sort(a+1,a+n+1,greater<int>());
for (int i=0;i<m;i++,st++) tm=i,solve(t==st,1);tm=m;out();printf("\n");
for (int i=1;i<=n+m;i++,st++) solve(t==st,0);out();
}