Advertisement
reverser1

Untitled

Apr 3rd, 2020
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.99 KB | None | 0 0
  1. #pragma GCC optimize("Ofast", "unroll-loops")
  2.  
  3. #define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  4. #include <iostream>
  5. #include <iomanip>
  6. #include <vector>
  7. #include <algorithm>
  8. #include <cmath>
  9. #include <string>
  10. #include <map>
  11. #include <unordered_map>
  12. #include <set>
  13. #include <unordered_set>
  14. #include <bitset>
  15. #include <sstream>
  16. #include <deque>
  17. #include <queue>
  18. #include <random>
  19. #include <cassert>
  20. #include <stack>
  21. #include <fstream>
  22.  
  23. using namespace std;
  24.  
  25. #define ll long long
  26. #define ld long double
  27. #define inf 1000000007
  28. #define all(a) a.begin(), a.end()
  29. #define files(in, out) freopen(in, "r", stdin); freopen(out, "w", stdout)
  30.  
  31. template<class T> inline void sort(T &a) { sort(all(a)); }
  32. template<class T> inline T sorted(T a) { sort(a); return a; }
  33. template<class T> inline istream& operator>>(istream& str, vector<T> &a) { for (auto &i : a) str >> i; return str; }
  34.  
  35. void solve() {
  36. int n, x;
  37. cin >> n >> x;
  38. vector<int> a;
  39. for (int k = 0; k < n; ++k) {
  40. int aa;
  41. cin >> aa;
  42. a.push_back(aa);
  43. }
  44. sort(all(a));
  45. int t = 0, tt = 0, xx = x;
  46. for (int i = 1; i <= n + xx; ++i) {
  47. for (int j = 0; j < n; ++j) {
  48. if (i != a[j] && j == n - 1) {
  49. //cout << "notfound " << i << ' ' << x << '\n';
  50. x--;
  51. a.push_back(i);
  52. tt++;
  53. }
  54. if (i == a[j]) {
  55. //cout << "found " << i << '\n';
  56. break;
  57. }
  58. }
  59. //cout << tt << '\n';
  60. if (x == 0) {
  61. break;
  62. }
  63. }
  64. sort(all(a));
  65. for (int l = 0; l < n+tt; ++l) {
  66. //cout << a[l] << ' ';
  67. if (a[l + 1] - a[l] > 1 || l == n+tt-1) {
  68. cout << a[l] << '\n';
  69. break;
  70. }
  71. }
  72. }
  73.  
  74. signed main() {
  75. FAST;
  76. // files("goat4.in", "goat4.out");
  77. int f = 1;
  78. cin >> f;
  79. while (f--) {
  80. solve();
  81. }
  82. return 0;
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement