/* -*- coding: utf-8 -*- * * 2680.cc: No.2680 研究室配属 - yukicoder */ #include #include using namespace std; /* constant */ const int MAX_N = 1000; const int MAX_M = 1000; /* typedef */ /* global variables */ int as[MAX_M], ts[MAX_N][MAX_M], ls[MAX_N]; /* subroutines */ /* main */ int main() { int n, m; scanf("%d%d", &n, &m); for (int j = 0; j < m; j++) scanf("%d", as + j); for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) scanf("%d", ts[i] + j); fill(ls, ls + n, -1); for (int j = 0; j < m; j++) { for (int i = 0; i < n; i++) if (ls[i] < 0 && as[ts[i][j]]) ls[i] = ts[i][j], as[ts[i][j]]--; } for (int i = 0; i < n; i++) printf("%d%c", ls[i], (i + 1 < n) ? ' ' : '\n'); return 0; }