int removeDishes(const vpii &pairs) { bool removedDish[n]; bool removedPair[pairs.size()]; fill(removedDish, removedDish+n, false); fill(removedPair, removedPair+pairs.size(), false); int count = 0; while (true) { int pairIndex = findRemovablePair(pairs, removedDish, removedPair); if (pairIndex < 0) { return count; } removedPair[pairIndex] = true; removedDish[pairs[pairIndex].first] = true; removedDish[pairs[pairIndex].second] = true; count += 2; } }
int findRemovablePair(const vpii &pairs, const bool* removedDish, const bool* removedPair) { for (int i = 0; i < pairs.size(); i++) { if (!removedPair[i] && removableDish(pairs[i].first, removedDish) && removableDish(pairs[i].second, removedDish)) { return i; } } return -1; }
int main () { srand (time (0)); //freopen (NAME".in", "r", stdin); //freopen (NAME".out", "w", stdout); scanf ("%d %d", &n, &k); for (int i = 0; i < n; i++) { int x; scanf ("%d", &x); a.pb (mp (x, i + 1)); } sort (a.begin (), a.end (), cmp); int curr = a [n - 1].frs - a [0].frs; while (curr > 1 && k > 0) { a [n - 1].frs--; a [0].frs++; ans.pb (mp (a [n - 1].snd, a [0].snd)); k--; sort (a.begin (), a.end (), cmp); curr = a [n - 1].frs - a [0].frs; } printf ("%d %d\n", curr, (int) ans.size ()); for (int i = 0; i < (int) ans.size (); i++) printf ("%d %d\n", ans [i].frs, ans [i].snd); return 0; }
void dfs(vvi& res, vi& cur, vpii& count, int idx) { string ident(idx * 4, ' '); if (idx == count.size()) { res.push_back(cur); return; } pii& p = count[idx]; int num = p.first, cnt = p.second; for (int rep = 0; rep <= cnt; ++rep) { for (int i = 0; i < rep; ++i) { cur.push_back(num); } dfs(res, cur, count, idx + 1); for (int i = 0; i < rep; ++i) { cur.pop_back(); } } }