Cod sursa(job #1238874)

Utilizator enedumitruene dumitru enedumitru Data 7 octombrie 2014 21:04:44
Problema Congr Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.85 kb
#include<algorithm>
#include<cstdio>
#include<ctime>
#define DIM 8192
#define ll long long
using namespace std;
int n,i,j,poz,p[600010],a[600010];
ll s;
char buff[DIM];
void cit(int &nr)
{   nr=0;
    while(buff[poz]<'0'||buff[poz]>'9')     
        if(++poz==DIM) fread(buff,1,DIM,stdin),poz=0;
    while('0'<=buff[poz]&&buff[poz]<='9')
    {   nr=nr*10+buff[poz]-'0';
        if(++poz==DIM) fread(buff,1,DIM,stdin),poz=0;               
    }     
}
int main()
{	freopen("congr.in","r",stdin); freopen("congr.out","w",stdout);
    cit(n);
    for(i=1;i<2*n;++i)
    {   cit(a[i]);
        if(i<=n) s+=a[i];
        p[i]=i;
    }
    srand(time(NULL));
    while(s%n)
    {   i=rand()%n+1; j=rand()%(n-1)+n+1;
        s=s-a[i]+a[j];
        swap(p[i],p[j]); swap(a[i],a[j]);
    }
    for(i=1;i<=n;++i) printf("%d ",p[i]);
    return 0;
}