// I expect this to be WA // approach: // randomly devide 2*n persons in two groups of n persons each // find optimal pairing between those groups // @EXPECTED_RESULTS@: WRONG_ANSWER,TIME_LIMIT_EXCEEDED #include using namespace std; #define all(x) begin(x), end(x) #define sz(x) (ll)(x).size() using ll = long long; using ld = long double; constexpr ll LIM = 4001; constexpr ll INF = 0x3FFF'FFFF'FFFF; ll costs[LIM][LIM]; // Es muss l<=r sein! (sonst Endlosschleife) ll match(int l, int r) { vector lx(l), ly(r); //xy is matching from l->r, yx from r->l, or -1 vector xy(l, -1), yx(r, -1), augmenting(r); vector s(l); vector> slack(r); for (int x = 0; x < l; x++) lx[x] = *max_element(costs[x], costs[x] + r); for (int root = 0; root < l; root++) { augmenting.assign(r, -1); s.assign(l, false); s[root] = true; for (int y = 0; y < r; y++) { slack[y] = {lx[root] + ly[y] - costs[root][y], root}; } int y = -1; while (true) { ll delta = INF; int x = -1; for (int yy = 0; yy < r; yy++) { if (augmenting[yy] < 0) { if (slack[yy].first < delta) { delta = slack[yy].first; x = slack[yy].second; y = yy; }}} if (delta > 0) { for (int x = 0; x < l; x++) if (s[x]) lx[x] -= delta; for (int y = 0; y < r; y++) { if (augmenting[y] >= 0) ly[y] += delta; else slack[y].first -= delta; }} augmenting[y] = x; x = yx[y]; if (x == -1) break; s[x] = true; for (int y = 0; y < r; y++) { if (augmenting[y] < 0) { ll alt = lx[x] + ly[y] - costs[x][y]; if (slack[y].first > alt) { slack[y] = {alt, x}; }}}} while (y >= 0) { // Jede Iteration vergrößert Matching um 1 // (können 0-Kanten sein!) int x = augmenting[y]; int prec = xy[x]; yx[y] = x; xy[x] = y; y = prec; }} // Wert des Matchings return accumulate(all(lx), 0ll) + accumulate(all(ly), 0ll); } ll n, r; vector> in; mt19937 rng(1234567890); bool solve() { vector perm(2*n); for (ll i = 0; i < 2*n; i++) perm[i] = i; for (ll _ = 0; _ < 5e7; _ += n*n*n) { for (ll i = 0; i < n; i++) { for (ll j = 0; j < n; j++) { costs[i][j] = 0; for (ll k = 0; k < r; k++) { costs[i][j] += max(in[k][perm[i]], in[k][perm[j+n]]); } } } if (2*match(n, n) >= r*n*(3*n+1)) return true; shuffle(all(perm), rng); } return false; } int main(int argc, char *argv[]) { ios_base::sync_with_stdio(false); cin.tie(nullptr); cin >> n >> r; in.assign(r, vector(2*n)); for (auto& v : in) { for (auto& x : v) cin >> x; } if (!solve()) cout << "im"; cout << "possible" << endl; }