Cod sursa(job #1395248)

Utilizator casuneanu.andreiCasuneanu Andrei Dan casuneanu.andrei Data 21 martie 2015 10:36:07
Problema Congr Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.68 kb
#include <fstream>
#include <cstdlib>
#include <ctime>
using namespace std;
#define IN "congr.in"
#define OUT "congr.out"

ifstream fin(IN);
ofstream fout(OUT);

int p;
int suma;
int v[300008];

int main()
{
    fin >>p;
    int i;
    for (i=1; i<=p*2-1; ++i){
        fin >>v[i];

        if (i<=p)
            suma+=v[i];
    }

    srand(time(NULL));
    int x, y;
    int aux;
    while (suma%p){
        x=1+rand()%p;
        y=p+rand()%p;

        suma-=v[x];
        suma+=v[y];

        aux=v[x];
        v[x]=v[y];
        v[y]=aux;
    }

    for (i=1; i<=p; ++i)
        fout <<v[i]<<' ';
    fout <<'\n';
    fout.close();
    return 0;
}