Cod sursa(job #2340366)

Utilizator AlexPop28Pop Alex-Nicolae AlexPop28 Data 10 februarie 2019 12:52:14
Problema Congr Scor 80
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.31 kb
#include <bits/stdc++.h>
#define all(cont) cont.begin(), cont.end()
#define pb push_back
#define fi first
#define se second
#define DEBUG(x) cerr << (#x) << ": " << (x) << '\n'

using namespace std;

typedef pair <int, int> pii;
typedef vector <int> vi;
typedef long long ll;
typedef unsigned long long ull;

template <class T> void uin (T &a, T b) {a = min (a, b);}
template <class T> void uax (T &a, T b) {a = max (a, b);}

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

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
#ifdef LOCAL_DEFINE
  freopen (".in", "r", stdin);
#endif

  srand (time (0));

  int n, sum = 0;
  f >> n;
  vi v (2 * n), ans (2 * n, 0);
  for (int i = 1; i <= 2 * n - 1; ++i) {
    f >> v[i];
    ans[i] = i;
    if (i <= n) (sum += v[i]) %= n;
  }

  auto random = [&] (int lo, int hi) {
    return lo + rand() % (hi - lo + 1);
  };

  while (sum != 0) {
    int sub = random (1, n);
    int add = random (n + 1, 2 * n - 1);

    (sum += v[add] - v[sub]) %= n;

    swap (v[sub], v[add]);
    swap (ans[sub], ans[add]);
  }

  for (int i = 1; i <= n; ++i) {
    g << ans[i] << ' ';
  }
  g << '\n';

  f.close();
  g.close();

#ifdef LOCAL_DEFINE
  cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
  return 0;
}