贪心,将W从大到小排序,每次选P-Q最小的。
#include <set>
#include <map>
#include <ctime>
#include <cmath>
#include <queue>
#include <cstdio>
#include <cctype>
#include <vector>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define MP make_pair
#define PB push_back
typedef long long LL;
typedef pair<int, int> pii;
inline int read()
{
int x = 0; int v = 1, c = getchar();
for(; c < '0' || c > '9'; c = getchar()) if(c == '-') v = -1;
for(;c >= '0' && c <= '9'; c = getchar()) x = x * 10 + c - '0';
return x * v;
}
template<typename T>
inline void write(T x, int ch = 10)
{
int s[20], t = 0;
if(x < 0) { x = -x; putchar('-'); }
do s[t++] = x % 10; while(x /= 10);
while(t--) putchar('0' + s[t]);
putchar(ch);
}
#define rep(i, a, b) for(register int i = (a); i <= (b); ++i)
const int maxn = 16005;
const int maxk = 105;
int n, k;
int w[maxn], p[maxn];
int num[maxk], q[maxk];
int orz[maxn], city[maxn];
void input()
{
k = read();
rep(i, 1, k) n += num[i] = read();
rep(i, 1, k) q[i] = read();
rep(i, 1, n) p[i] = read();
rep(i, 1, n) w[i] = read();
}
bool cmp(int a, int b)
{
return w[a] > w[b];
}
void solve()
{
rep(i, 1, n) orz[i] = i;
sort(orz + 1, orz + n + 1, cmp);
rep(i, 1, n)
{
int xj = 0, Min = 2e9;
rep(j, 1, k)
{
if(num[j] && p[orz[i]] > q[j])
{
int tmp = p[orz[i]] - q[j];
if(tmp < Min)
{
Min = tmp;
xj = j;
}
}
}
if(xj)
{
city[orz[i]] = xj;
num[xj]--;
}
}
rep(i, 1, n) if(!city[i])
rep(j, 1, k)
if(num[j])
{
num[j]--;
city[i] = j;
break;
}
}
void output()
{
rep(i, 1, n) write(city[i], ' ');
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
input();
solve();
output();
#ifndef ONLINE_JUDGE
fprintf(stderr, "Run Time: %dms\n", clock());
fclose(stdin), fclose(stdout);
#endif
return 0;
}