Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define F first
- #define S second
- #define endl '\n'
- #define pb push_back
- #define ll long long
- using namespace std;
- vector < int > g[5];
- int main() {
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- int n;
- int m[3];
- cin >> n >> m[0] >> m[1] >> m[2];
- // if(n != 3 && n != 5 && n != 7) {
- // while(1) {
- //
- // }
- // }
- int l = 1, r = 1;
- for(int i = 0; i < 3; ++i) {
- for(int j = 0; j < m[i]; ++j) {
- int x;
- cin >> x;
- x += 2;
- g[i].pb(x);
- }
- r = max(r, int32_t(g[i].size()));
- }
- vector < int > used(n + 5);
- int cnt[5];
- int ans = 1;
- // cout << l << " " << r << endl;
- // for(int i = 0; i < 3; ++i) {
- // cout << i << ": ";
- // for(auto to : g[i])
- // cout << to << " ";
- // cout << endl;
- // }
- // return 0;
- while(l <= r) {
- int mid = (l + r) / 2;
- // cerr << l << " " << r << " " << mid << endl;
- if(mid * 3 > n) {
- // cerr << "lol " << endl;
- r = mid - 1;
- continue;
- }
- // if(mid == 3) cerr << "kek " << endl;
- // cerr << mid << endl;
- bool f = 1;
- for(int i = 0; i < n + 5; ++i) used[i] = -1;
- cnt[0] = 0;
- cnt[1] = 0;
- cnt[2] = 0;
- for(int i = 0; i < 3; ++i) {
- for(auto to : g[i]) {
- if(used[to] == -1) {
- cnt[i]++;
- used[to] = i;
- continue;
- }
- int x = used[to];
- if(cnt[x] - 1 >= mid) {
- cnt[x]--;
- cnt[i]++;
- used[to] = i;
- }
- }
- }
- for(int i = 0; i < 3; ++i) {
- if(cnt[i] < mid)
- f = 0;
- }
- if(f) {
- l = mid + 1;
- ans = mid;
- } else
- r = mid - 1;
- }
- used.assign(n + 5, -1);
- cnt[0] = 0;
- cnt[1] = 0;
- cnt[2] = 0;
- for(int i = 0; i < 3; ++i) {
- for(auto to : g[i]) {
- if(used[to] == -1) {
- cnt[i]++;
- used[to] = i;
- continue;
- }
- int x = used[to];
- if(cnt[x] - 1 >= ans) {
- cnt[x]--;
- cnt[i]++;
- used[to] = i;
- }
- }
- }
- for(int i = 3; i < n + 3; ++i) {
- cout << used[i] + 1 << " ";
- }
- // cout << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement