fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define speed ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  5. #define v_in(v , n , type) for(int i = 0 ; i < n ; i++) {type x ; cin>> x; v.push_back(x);}
  6. #define ok(check) if(check) cout <<"YES\n" ; else cout <<"NO\n";
  7. #define all(v) v.begin(),v.end()
  8. #define F first
  9. #define S second
  10. const int N = 2e5 + 10;
  11. const ll oo = 1e15;
  12. vector<int> v;
  13. int n, k;
  14.  
  15.  
  16. void testcase()
  17. {
  18. cin >> n >> k;
  19. vector<ll> prefix(n + 10, 0);
  20. for (int i = 0; i < n; i++)
  21. {
  22. int x;
  23. cin >> x;
  24. v.push_back(x);
  25. prefix[x]++;
  26. prefix[x + 1]--;
  27.  
  28. if (x % 2 == 0)
  29. {
  30. prefix[x / 2]++;
  31. prefix[x / 2 + 1]--;
  32. }
  33. if (x % 3 == 0)
  34. {
  35. prefix[x / 3]++;
  36. prefix[x / 3 + 1]--;
  37. }
  38.  
  39. prefix[0]++;
  40. prefix[x / 4 + 1]--;
  41. }
  42. for (int i = 1; i <= n; i++)
  43. {
  44. prefix[i] += prefix[i - 1];
  45. }
  46. ll ans=0;
  47. for (int i = 1; i <= n; i++)
  48. {
  49. if (prefix[i] + k >= n)ans = i;
  50. }
  51. cout<<ans<<endl;
  52. }
  53.  
  54. int main()
  55. {
  56. #ifndef ONLINE_JUDGE
  57. freopen("input.txt", "r", stdin);
  58. freopen("output.txt", "w", stdout);
  59. #endif
  60. speed
  61. int t = 1;
  62. cin >> t;
  63. while (t--)
  64. {
  65. testcase();
  66. }
  67. return 0;
  68. }
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
0