Cod sursa(job #1822895)

Utilizator TimitocArdelean Andrei Timotei Timitoc Data 5 decembrie 2016 18:51:53
Problema Congr Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.11 kb
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#define MAXN 300010
#define DIM 100000

using namespace std;

int n, p, poz;
int a[MAXN], b[MAXN], val[2*MAXN];
char buf[DIM];

void read (int &numar)
{
    numar = 0;
    while (buf[poz] < '0' || buf[poz] > '9')
        if (++poz == DIM)
            fread(buf,1,DIM,stdin),poz=0;
    while ('0'<=buf[poz] && buf[poz]<='9')
    {
        numar = numar*10 + buf[poz] - '0';
        if (++poz == DIM)
            fread(buf,1,DIM,stdin),poz=0;
    }
}

int main()
{
    freopen("congr.in", "r", stdin);
    freopen("congr.out", "w", stdout);
    fread(buf,1,DIM,stdin);

    srand(time(0));
    read(n);
    long long sum = 0;
    for (int i = 1, k = 2*n-1; i <= k; i++) {
        read(val[i]);
        if (i <= n) {
            a[i] = i;
            sum += val[i];
        }
        else
            b[i-n] = i;
    }
    while (sum % n) {
        int i = rand() % n + 1;
        int j = rand() % (n-1) + 1;
        sum = sum - val[a[i]] + val[b[j]];
        swap(a[i], b[j]);
    }
    for (int i = 1; i <= n; i++)
        printf("%d ", a[i]);

    return 0;
}