-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2060B.cpp
More file actions
60 lines (48 loc) · 1.4 KB
/
2060B.cpp
File metadata and controls
60 lines (48 loc) · 1.4 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// coded by Cocane
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define forn(i, n) for (int i = 0; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define pb push_back
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
int t; // Number of test cases
cin >> t;
while (t--) {
int n, m;
cin >> n >> m;
vector<vector<int>> cards(n); // Cards for each cow
forn(i, n) {
cards[i].resize(m);
forn(j, m) cin >> cards[i][j];
sort(all(cards[i])); // Sort cards for each cow
}
vector<int> order(n);
iota(all(order), 1);
sort(all(order), [&](int i, int j) {
return cards[i - 1][0] < cards[j - 1][0];
});
int tpCard = -1;
bool poss = true;
for (int rnd = 0; rnd < m && poss; rnd++) {
for (int i : order) {
auto &deck = cards[i - 1];
if (deck.empty() || deck[0] <= tpCard) {
poss = false;
break;
}
tpCard = deck[0];
deck.erase(deck.begin());
}
}
if (poss) {
for (int i : order) cout << i << " ";
cout << endl;
} else {
cout << -1 << endl;
}
}
return 0;
}