#include <bits/stdc++.h> typedef long long ll; const int maxx = 100010; const int inf = 0x3f3f3f3f; const int mod = 1000000009; using namespace std; int a[110]; int cnt[1010]; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t, n, x; cin >> t; while (t--) { cin >> n >> x; memset(cnt, 0, sizeof(cnt)); for (int i = 0; i < n; i++) { cin >> a[i]; cnt[a[i]]++; } int k = 0; for (int i = 1; x; i++) { if (cnt[i] == 0) x--, k = i, cnt[i]++; } for (int i = k;; i++) { if (cnt[i] == 0) { k = i - 1; break; } } printf("%d\n", k); } return 0; }
#include <bits/stdc++.h> typedef long long ll; const int maxx = 200010; const int inf = 0x3f3f3f3f; using namespace std; int a[maxx], p[maxx], q[maxx]; int t, n, l, r; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> t; while (t--) { cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; set<int> s; for (int i = 1; i <= n; i++) { if (s.find(a[i]) == s.end()) { s.insert(a[i]); } else { l = i - 1; break; } } s.clear(); for (int i = n; i >= 1; --i) { if (s.find(a[i]) == s.end()) { s.insert(a[i]); } else { r = i + 1; break; } } for (int i = 1; i <= n; i++) p[i] = max(p[i - 1], a[i]); for (int i = n; i >= 1; --i) q[i] = max(q[i + 1], a[i]); vector<int> ans; for (int i = 1; i < n; i++) { if (i <= l && i + 1 >= r && p[i] == i && q[i + 1] == n - i) { ans.push_back(i); } } cout << ans.size() << endl; for (int i : ans) cout << i << " " << n - i << endl; for (int i = 1; i <= n; i++) p[i] = q[i] = 0; } return 0; }
#include <bits/stdc++.h> typedef long long ll; const int maxx = 100010; const int inf = 0x3f3f3f3f; using namespace std; ll a[maxx], sum[maxx]; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, m; cin >> n >> m; for (int i = 1; i <= m; i++) cin >> a[i]; for (int i = 1; i <= m; i++) { if (n - a[i] + 1 < i) { cout << "-1" << endl; return 0; } } memset(sum, 0, sizeof(0)); for (int i = m; i >= 1; i--) sum[i] = sum[i + 1] + a[i]; if (sum[1] < n) { cout << "-1" << endl; return 0; } for (int i = 1; i <= m; i++) { int ans = max(1ll * i, n - sum[i] + 1); cout << ans << " "; } return 0; }