Spiral line

A bunch of villains are waiting in line for being accepted on board of the Queen Anne’s Revenge, docked somewhere in Nassau, to become part of the crew. Every rascal is represented by a number corresponding to the “pieces of eight” they have stolen so far. However, the pirates of the Queen Anne’s Revenge are as crazy as the captain and arrange that line in a spiral: Rascals that make it wrong will walk the plank! [Read More]

Students arrangement

Solutions First of all, we sort both the series in non-decreasing order, then we simply check if alternating boys and girls is feasible according to the rules: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 int T, N; cin >> T; while (T--) { cin >> N; array<vector<int>, 2> v = {vector<int>(N), vector<int>(N)}; copy_n(istream_iterator<int>(cin), N, begin(v[0])); copy_n(istream_iterator<int>(cin), N, begin(v[1])); sort(begin(v[0]), end(v[0])); sort(begin(v[1]), end(v[1])); auto m = mismatch(begin(v[0]), end(v[0]), begin(v[1]), end(v[1])); if (m. [Read More]
sort  ad-hoc