fork download
  1.  
  2. //================================================= includes ===================================================//
  3.  
  4. #include <bits/stdc++.h>
  5. #include <iostream>
  6. #include <vector>
  7. using namespace std;
  8.  
  9. //=========================================================== define =======================================================================================//
  10.  
  11. #define Essam_z ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  12. #define nl cout << '\n';
  13. #define ll long long
  14. #define ld long double
  15. #define str string
  16. #define YES cout << "YES\n";
  17. #define NO cout << "NO\n";
  18. #define fxd(n) fixed << setprecision(n) // cout
  19. #define pi 3.14159265359
  20. #define loopr(i, a, b) for(int i = a; i <= b; ++i)
  21. #define loop(i, n) for(int i = 0; i < n; ++i)
  22. #define sorts(X) sort(X.begin(), X.end())
  23. #define sortt(X, n) sort(X, X + n)
  24. #define rev(X, n) reverse(X, X + n)
  25. #define all(X) X.begin(), X.end()
  26. #define sz size()
  27. #define F first
  28. #define S second
  29.  
  30. //=========================================================== functions =======================================================================================//
  31.  
  32. ll gcd(ll a, ll b) {
  33. if (b == 0) return a;
  34. return gcd(b, a % b);
  35. }
  36. ll lcm(ll a, ll b) {
  37. return (a / gcd(a, b)) * b;
  38. }
  39. ll sums(ll n) {
  40. return (n * (n + 1) / 2);
  41. }
  42. ll sumrng(ll n, ll m) {
  43. return (((n + m) * (m - n + 1)) / 2);
  44. }
  45. ll sumodd(ll n) {
  46. ll res = (n + 1) / 2;
  47. return res * res;
  48. }
  49. ll sumeven(ll n) {
  50. n /= 2;
  51. ll res = n * (n + 1);
  52. return res;
  53. }
  54. ll fact(ll n) {
  55. if (n == 0 || n == 1) return 1;
  56. return n * fact(n - 1);
  57. }
  58. bool isprime(ll n) {
  59. if (n <= 1) return false;
  60. for (ll i = 2; i * i <= n; ++i) {
  61. if (n % i == 0) return false;
  62. }
  63. return true;
  64. }
  65. bool ispalindrom(str s) {
  66. int i = 0, j = s.size() - 1;
  67. while (i <= j) {
  68. if (s[i] != s[j]) return false;
  69. ++i;
  70. --j;
  71. }
  72. return true;
  73. }
  74. bool islucky(int n) {
  75. while (n > 0) {
  76. if (n % 10 != 4 && n % 10 != 7) return false;
  77. n /= 10;
  78. }
  79. return true;
  80. }
  81. ll npr(ll n, ll r) {
  82. return fact(n) / fact(n - r);
  83. }
  84. ll ncr(ll n, ll r) {
  85. return fact(n) / (fact(r) * fact(n - r));
  86. }
  87. ll diff_strings(str s1, str s2) {
  88. ll sum = 0;
  89. for (int i = 0; i < s1.sz; ++i) {
  90. sum += abs(s1[i] - s2[i]);
  91. }
  92. return sum;
  93. }
  94. ll sum_div_x(ll a, ll b, ll x) {
  95. ll mx = max(a, b);
  96. ll mn = min(a, b);
  97. ll sum = (sums(mx / x) * x) - (sums((mn - 1) / x)) * x;
  98. return sum;
  99. }
  100. int dx[]={
  101. -1, -1, -1,
  102. 0, 0,
  103. 1, 1, 1
  104. }; // for checking grid
  105. int dy[]={
  106. -1, 0, 1,
  107. -1, 1,
  108. -1, 0, 1
  109. };
  110.  
  111. //============================================================= // I am Not tourist // ===============================================================//
  112.  
  113.  
  114. int main() {
  115.  
  116. int n,k; cin>>n>>k;
  117.  
  118.  
  119. int freq[2][200001]{0};
  120.  
  121.  
  122.  
  123. for (int i = 0 ; i < n; i++)
  124. {
  125. int num; cin>>num;
  126.  
  127. freq[1][num]++;
  128.  
  129.  
  130.  
  131. }
  132.  
  133.  
  134.  
  135. for (int i = -k ; i <=k ; i++)
  136. {
  137. if (freq[1][i]==0)
  138. {
  139. cout<<i;
  140.  
  141. break;
  142. }
  143. }
  144.  
  145. return 0;
  146. }
Success #stdin #stdout 0.01s 5280KB
stdin
7 5
-1 4 -5 3 -2 -3 4
stdout
-4