Cod sursa(job #1395295)

Utilizator casuneanu.andreiCasuneanu Andrei Dan casuneanu.andrei Data 21 martie 2015 10:48:21
Problema Congr Scor 90
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.77 kb
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <ctime>
using namespace std;

#define Nmax 600002

FILE *f = fopen ( "congr.in" , "r" );
FILE *g = fopen ( "congr.out" , "w" );

int v[Nmax], sol[Nmax];

int main(){
    int N, x, y;
    long long S = 0;

    fscanf ( f, "%d", &N );

    srand (time (NULL));

    for ( int i = 1; i < 2 * N; ++i ){
        fscanf ( f,"%d", &v[i] );
        sol[i] = i;
        if ( i <= N )
            S += v[i];
    }

    while ( S % N ){
        x = 1 + rand () % N;
        y = N + 1 + rand () % (N - 1);

        S = S - v[x] + v[y];
        swap ( sol[x], sol[y] );
        swap ( v[x], v[y] );
    }

    for ( int i = 1; i <= N; ++i )
        fprintf ( g, "%d ", sol[i] );

    return 0;
}