intmain(){ int _; cin >> _; for (int ts = 0; ts < _; ++ts) { int n, k; cin >> n >> k; vector<int> data(n); for (int i = 0; i < n; ++i) cin >> data[i]; if (k > 10000) cout << -1 << endl; else { int last = -1; for (int i = 0; i < k; ++i) { int cur = 0; while (cur < n - 1 && data[cur + 1] <= data[cur]) cur++; if (cur == n - 1) last = -1; else { data[cur]++; last = cur + 1; } } cout << last << endl; } } }
voidsolve(){ int _; cin >> _; for (int ts = 0; ts < _; ++ts) { int n, m; cin >> n >> m; vector<int> a(n), b(n), c(m), res(m, 0); map<int, vector<int>> data; for (int i = 0; i < n; ++i) cin >> a[i]; for (int i = 0; i < n; ++i) { cin >> b[i]; if (a[i] != b[i]) data[b[i]].push_back(i + 1); } for (int i = 0; i < m; ++i) cin >> c[i]; for (int i = 0; i < m; ++i) { auto iter = data.find(c[i]); if (iter == data.end()) continue; res[i] = iter->second.back(); iter->second.pop_back(); if (iter->second.size() == 0) data.erase(iter); } if (res.back() == 0) for (int i = 0; i < n; ++i) if (c.back() == b[i]) res.back() = i + 1; for (auto &item : res) if (item == 0) item = res.back(); if (res.back() == 0 || !data.empty()) cout << "NO" << endl; else { cout << "YES" << endl; for (int i = 0; i < res.size(); ++i) cout << res[i] << " \n"[i == res.size() - 1]; } } }
intmain(){ int _; cin >> _; for (int ts = 0; ts < _; ++ts) { int n, m; cin >> n >> m; vector<string> g(n); for (auto &item : g) item.reserve(n); for (int i = 0; i < n; ++i) cin >> g[i];
if (n == 2) { if (g[0][1] == g[1][0] || m % 2 == 1) { cout << "YES" << endl; for (int i = 0; i < m + 1; ++i) cout << (i % 2) + 1 << " \n"[i == m]; } else { cout << "NO" << endl; } } else { vector<int> tmp(3); for (int i = 0; i < 3; ++i) tmp[i] = i; do { if (g[tmp[0]][tmp[1]] == g[tmp[1]][tmp[2]]) break; } while (next_permutation(tmp.begin(), tmp.end()));
assert(g[tmp[0]][tmp[1]] == g[tmp[1]][tmp[2]]); int cur = (m + 1) % 3;
cout << "YES" << endl; for (int i = 0; i < m + 1; ++i) cout << tmp[(i + cur) % 3] + 1 << " \n"[i == m]; } } }