Cod sursa(job #1822891)

Utilizator TimitocArdelean Andrei Timotei Timitoc Data 5 decembrie 2016 18:44:40
Problema Congr Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.02 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];
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++) {
		int x;
		read(x);
		if (i <= n) {
			a[i] = x;
			sum += x;
		}
        else
			b[i-n] = x;
    }
    while (sum % n) {
        int i = rand() % n + 1;
        int j = rand() % (n-1) + 1;
        sum = sum - a[i] + b[j];
        swap(a[i], b[j]);
    }
	for (int i = 1; i <= n; i++)
		printf("%d ", a[i]);

	return 0;
}