#include<iostream> #include<algorithm> #include<vector> #include<cmath> #define maxn 11 #define maxm 10010 #define ll long long usingnamespacestd;
int n, m, a[maxn], cnt[maxm]; char s[maxn][maxm];
int Ans[maxm]; voidwork(){ cin >> n >> m; for (int i = 1; i <= n; ++i) cin >> a[i]; for (int i = 1; i <= n; ++i) cin >> s[i] + 1; int M = (1 << n) - 1; ll ans = 0; for (int S = 0; S <= M; ++S) { ll sum = 0; for (int i = 1; i <= m; ++i) cnt[i] = 0; for (int i = 1; i <= n; ++i) { int opt = (S >> i - 1 & 1) ? 1 : -1; sum -= opt * a[i]; for (int j = 1; j <= m; ++j) if (s[i][j] == '1') cnt[j] += opt; } vector<pair<int, int>> vec; for (int i = 1; i <= m; ++i) vec.emplace_back(cnt[i], i); sort(vec.begin(), vec.end()); for (int i = 0; i < m; ++i) sum += 1ll * vec[i].first * (i + 1); if (sum >= ans) { for (int i = 0; i < m; ++i) Ans[vec[i].second] = i + 1; ans = sum; } } for (int i = 1; i <= m; ++i) cout << Ans[i] << " \n"[i == m]; }