https://codeforc.es/gym/101987
思路:对于每一天要用的人取出可以工作的,优先选择工作天数多的进行工作;
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <map>
#include <set>
using namespace std;
#define sfi(x) scanf("%d",&x)
#define sfc(x) scanf("%c",x)
#define sfl(x) scanf("%lld",&x)
#define sfs(x) scanf("%s",x)
#define pb push_back
#define fl() printf("flag!\n")
#define INF 0x3f3f3f3f
#define ll long long
#define mem(x,y) memset(x,y,sizeof(x))
#define FAST_IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
const int maxn=2e5+9;
const int mod=1e9+7;
struct node
{
int id,st;
int day;
bool operator < (const node &b) const
{
if(st==b.st) return day<b.day;
else return st>b.st;
}
}a[maxn];
struct node2
{
int id,st;
int day;
bool operator < (const node2 &b) const
{
return day<b.day;
}
};
priority_queue<node2>qq;
priority_queue<node>q;
priority_queue<int,vector<int>,greater<int> >dn;
vector<int>ans[maxn];
int d[maxn];
int main()
{
//FAST_IO;
//freopen("input.txt","r",stdin);
int m,n,w,h;
while(cin>>m>>n>>w>>h)
{
bool f=1;
int us=0;
for(int i=0;i<=m;i++) ans[i].clear();
while(q.size()) q.pop();
while(qq.size()) qq.pop();
while(dn.size()) dn.pop();
for(int i=1;i<=m;i++)
{
cin>>a[i].day;
a[i].st=1;
a[i].id=i;
q.push(a[i]);
}
for(int i=1;i<=n;i++)
{
cin>>d[i];
}
for(int i=1;i<=n;i++)
{
while(dn.size())
{
if(dn.top()<i) dn.pop();
else break;
}
if(dn.size()==d[i]) continue;
if(dn.size()>d[i])
{
//fl();
f=0;
break;
}
while(q.size()&&q.top().st<=i)
{
node tmp=q.top();
q.pop();
node2 tmp2;
tmp2.id=tmp.id;
tmp2.st=tmp.st;
tmp2.day=tmp.day;
qq.push(tmp2);
}
//cout<<qq.size()<<" ";
int yu=d[i]-dn.size();
while(qq.size()&&yu--)
{
node2 tmp2=qq.top();
qq.pop();
tmp2.st=i+w-1;
tmp2.day-=w;
dn.push(tmp2.st);
tmp2.st+=h+1;
ans[tmp2.id].pb(i);
node tmp;
tmp.st=tmp2.st;
tmp.day=tmp2.day;
tmp.id=tmp2.id;
if(tmp.day>0)
{
q.push(tmp);
}
else us++;
}
//cout<<dn.size()<<" ";
if(dn.size()!=d[i])
{
//fl();
f=0;
break;
}
if(!f) break;
}
if(us!=m) f=0;
if(!f) puts("-1");
else
{
cout<<1<<endl;
for(int i=1;i<=m;i++)
{
for(int j=0;j<ans[i].size();j++)
{
if(j!=0) cout<<" ";
cout<<ans[i][j];
}
cout<<endl;
}
}
}
return 0;
}