Cod sursa(job #3147069)

Utilizator DariusM17Murgoci Darius DariusM17 Data 23 august 2023 22:52:56
Problema Congr Scor 10
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.86 kb
//#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;
const string file = "congr";
ifstream cin(file + ".in");
ofstream cout(file + ".out");
#define FAST ios_base::sync_with_stdio(0), cin.tie(0),cout.tie(0) ;
int  n, a[300005], b[300005], s, x, ans[300005],ansd[300005];
int main(void)
{
    cin >> n;
    for (int i = 1; i <= 2 * n - 1; ++i) {
        cin >> x;
        if (i <= n) {
            a[++a[0]] = x % n;
            s += a[a[0]];
            ans[i] = i;
        }
        else b[++b[0]] = x % n, ansd[++ansd[0]] = i;
    }
    srand(time(0));
    while (s % n != 0) {
        int st = rand() % n + 1, dr = (rand() % (n - 1)) + 1;
        s -= a[st], s += b[dr];
        swap(ans[st], ansd[dr]);
    }
    for (int i = 1; i <= n; ++i) cout << ans[i] << " ";
    return 0;
}