Cod sursa(job #1314726)

Utilizator vladia13Ungureanu Adrian vladia13 Data 12 ianuarie 2015 10:58:51
Problema Congr Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.73 kb
#include <fstream>
#include <ctime>
#include <cstdlib>

using namespace std;

int x, i, j, aux, a[2 * 300005], poz[2 * 300005];
long long sum;

int main()
{
    ifstream f("congr.in");
    ofstream g("congr.out");

    srand(time(0));
    f >> x;
    for (i = 1; i <= 2*x - 1; i++)
    {
        f >> a[i];
        poz[i] = i;
        }

    for (i = 1; i <= x; i++)
        sum += a[i];

    while (sum % x != 0)
    {
          i = 1 + rand() % x;
          j = x + 1 + rand() % (x - 1);
          sum += a[poz[j]];
          sum -= a[poz[i]];
          aux = poz[i];
          poz[i] = poz[j];
          poz[j] = aux;
          }

    for (i = 1; i <= x; i++)
        g << poz[i] << " ";

return 0;
}