Cod sursa(job #882208)

Utilizator ericptsStavarache Petru Eric ericpts Data 18 februarie 2013 22:29:36
Problema Congr Scor 70
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.73 kb
#include <fstream>
#include <cstdlib>
#include <time.h>

using namespace std;

ifstream in("congr.in");
ofstream out("congr.out");

#define maxn 300003

int show[maxn];
int v[maxn];
int n;
long long S;

int main()
{
    int i;
    in >> n;
    srand(time(NULL));
    for(i=1;i<2*n;++i)
    {
        in >> v[i];
        if(i <= n)
            S += v[i];
        show[i]=i;
    }
    int idx1,idx2;
    while(S % n)
    {
        idx1 = 1 + rand() % n;
        idx2 = n + rand() % n;
        idx2 += idx2==n;
        S = S - v[idx1] + v[idx2];
        swap(v[idx1],v[idx2]);
        swap(show[idx1],show[idx2]);
    }
    for(i=1;i<=n;++i)
        out << show[i] << " ";
    out << "\n";
    return 0;
}