int n, k, a[maxn], cnt[maxn], last[maxn], ans[maxn];
intmain(){ scanf("%d%d", &n, &k); for (int i = 1; i <= n; i++) scanf("%d", a + i), cnt[a[i]]++; int s = 1; for (int i = 1; i <= 5000; i++) { if (cnt[i] > k) returnputs("NO"); last[i] = s; s = (s + cnt[i] + k - 1) % k + 1; } puts("YES"); int tot = 0; for (int i = 1; i <= n; i++) { last[a[i]] = last[a[i]] % k + 1; ans[i] = last[a[i]]; } for (int i = 1; i <= n; i++) { printf("%d ", ans[i]); } return0; }
intmain(){ scanf("%d%d%d", &n, &x, &y); for (int i = 1; i <= n; i++) scanf("%d", a + i); if (x > y) returnprintf("%d", n), 0; int ans = 1; for (int i = 1; i <= n; i++) if (a[i] <= x) ans++; cout << ans / 2; // int ans = 0; // while (true) { // auto r = st.upper_bound(x); // if (r == st.begin()) break; // r--; ans++; // st.erase(r); // st.erase(*st.begin()); // } // cout << ans; return0; }
int n, m, a[20][10000 + 10], vis[30], lk[30][30], ck[30][30]; vector<int> edge[20];
int s, tag, mask[maxn][20]; intdfs(int u, int cnt, int mk){ if (cnt == n) { if (ck[s][u] < tag) return0; return1; } mk |= (1 << u); if (mask[mk][u] == s) return0; for (int& v: edge[u]) { if (vis[v]) continue; vis[v] = 1; if (dfs(v, cnt + 1, mk)) return1; vis[v] = 0; } mask[mk][u] = s; return0; } intcheck(int x){ tag = x; for (int i = 1; i <= n; i++) edge[i].clear(); for (int i = 1; i <= n; i++) { for (int j = i + 1; j <= n; j++) { if (lk[i][j] >= x) { edge[i].push_back(j); edge[j].push_back(i); } } } ms(vis, 0); ms(mask, 0); for (int i = 1; i <= n; i++) { s = i; vis[s] = 1; if (dfs(s, 1, 0)) return1; vis[s] = 0; } return0; }
intmain(){ scanf("%d%d", &n, &m); for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) scanf("%d", &a[i][j]); for (int i = 1; i <= n; i++) for (int j = i + 1; j <= n; j++) { int mn = 1e9; for (int k = 1; k <= m ; k++) { mn = min(mn, abs(a[i][k] - a[j][k])); } lk[i][j] = mn; } for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) { int mn = 1e9; for (int k = 2; k <= m; k++) { mn = min(mn, abs(a[i][k] - a[j][k - 1])); } ck[i][j] = mn; } int l = 0, r = 1e9, ans = 0; while (l <= r) { int m = l + r >> 1; if (check(m)) l = m + 1, ans = m; else r = m - 1; } cout << ans; return0; }