Cod sursa(job #466930)

Utilizator Pepelea_FlaviuFlaviu Pepelea Pepelea_Flaviu Data 27 iunie 2010 22:32:22
Problema Congr Scor 50
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.94 kb
# include <cstdio>
# include <stdlib.h>
# include <time.h>

using namespace std;

# define FIN "congr.in"
# define FOUT "congr.out"
# define MAX_N 300005

int P, i, j, s, aux;
int A[MAX_N];
int Ind[2][MAX_N];

    int main() {
        
        freopen(FIN, "r", stdin);
        freopen(FOUT, "w", stdout);
        
        srand(time(0));
        
        scanf("%d", &P);
        for (i = 1; i < P << 1; ++i) {
            scanf("%d", &A[i]);
            i <= P ? Ind[0][i] = i, s += A[i] : Ind[1][i - P] = i;
        }
           
        while (s % P != 0) {
            i = rand() % P + 1;
            j = rand() % (P - 1) + 1;
            
            s -= A[Ind[0][i]];
            s += A[Ind[1][j]];
            
            aux = Ind[0][i];
            Ind[0][i] = Ind[1][j];
            Ind[1][j] = aux;
        }
        
        for (i = 1; i <= P; ++i) printf("%d ", Ind[0][i]);
        
        return 0;
    }