-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path10249.cpp
More file actions
128 lines (117 loc) · 1.86 KB
/
10249.cpp
File metadata and controls
128 lines (117 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#include<stdio.h>
#include<iostream>
#include<math.h>
#include<string.h>
#include<string>
#include<stdlib.h>
#include<map>
#include<vector>
#include<queue>
#include<stack>
#include<algorithm>
#include<set>
using namespace std;
// Define Some Variables
#define eps 1e-14
#define si 101
#define pi acos(-1.0)
#define inf (1<<30)-1
//Define Some Functions
#define even(a) ((a)%2==0)
#define odd(a) ((a)%2==1)
#define max(a,b) (a>b ?a:b)
#define min(a,b) (a<b ?a:b)
#define sqr(a)((a)*(a))
#define area(x1,y1,x2,y2,x3,y3) (x1*(y2-y3)+x2*(y3-y1)+x3*(y1-y2)) //Area of a triangle
#define distance(x1,y1,x2,y2) (sqr(x1-x2)+sqr(y1-y2)) //Distance between two points
#define FOR(i,a,b) for(i=a;i<=b;i++)
#define rep(i,a,b) for(i=a;i<b;i++)
#define rev(i,a,b) for(i=a;i>=b;i--)
//typedef __int64 i64;
int i,j,l,n,x=1,sm,cnt,fg,mx_tm,mx_tb,m,mx;
vector<int>ve[si];
int gcd(int a,int b)
{
while(b>0)
{
a%=b;
a^=b;
b^=a;
a^=b;
}
return a;
}
struct ss
{
int n,ind;
}tm[si],tb[si];
bool cmp(ss aa, ss bb)
{
return aa.n<bb.n;
}
int main()
{
while(~scanf("%d%d",&m,&n)&&(m||n))
{
sm=cnt=0;
fg=1;
rep(i,0,m)
{
scanf("%d",&tm[i].n);
tm[i].ind=i+1;
}
sort(tm,tm+m,cmp);
rep(i,0,n)
{
scanf("%d",&tb[i].n);
tb[i].ind=i+1;
}
sort(tb,tb+n,cmp);
rev(i,m-1,0)
{
mx=tm[i].n;
int u=tm[i].ind;
rev(j,n-1,0)
{
if(tb[j].n==0)
continue;
tb[j].n--;
mx--;
ve[u].push_back(tb[j].ind);
if(mx==0)
break;
}
sort(tb,tb+n,cmp);
if(mx)
{
fg=0;
break;
}
}
if(!fg)
printf("0\n");
else
{
printf("1\n");
FOR(i,1,m)
{
fg=1;
l=ve[i].size();
rep(j,0,l)
{
if(fg)
{
fg=0;
printf("%d",ve[i][j]);
}
else
printf(" %d",ve[i][j]);
}
puts("");
}
}
for(i=1;i<=m;i++)
ve[i].clear();
}
return 0;
}