fork download
  1. #include <bits/stdc++.h> // NeOWami
  2. using namespace std;
  3.  
  4. #define ft first
  5. #define sc second
  6. #define int long long
  7. const int N = 2e5 + 20;
  8. int n, ps[N], k;
  9. int a[N];
  10. void solve() {
  11. cin >> n >> k;
  12. for (int i = 1; i <= n; i++) cin >> a[i];
  13. fill(ps, ps + n + 5, 0);
  14.  
  15. for (int i = 1; i <= n; i++) {
  16. int tmp = -1;
  17. int x = 0;
  18. if (a[i] % 3 == 0) {
  19. tmp = a[i] / 3;
  20. }
  21. x = max((int)1, a[i] / 4);
  22. while(x > 1) {
  23. int y = (a[i] - 2 * x) / x, z = a[i] % x;
  24. // cerr << "FUC " << a[i] << " " << x << " " << y << " " << z << "\n";
  25. if (y >= 1 && x + z <= y * x) break;
  26. x--;
  27. }
  28. if (tmp != -1) ps[tmp]++, ps[tmp + 1]--;
  29. ps[1]++;
  30. ps[x + 1]--;
  31. // ps[a[i]]++;
  32. // ps[a[i] + 1]--;
  33. // cerr << 1 << " -> " << x << "| ";
  34. for (int j = 1; j * j <= a[i]; j++) {
  35. if (a[i] % j == 0) {
  36. if (j > x && j != tmp) {
  37. ps[j]++;
  38. ps[j + 1]--;
  39. // cerr << j << " ";
  40. }
  41. if (a[i] / j != j && a[i] / j > x && a[i] / j != tmp) {
  42. ps[a[i] / j]++;
  43. ps[(a[i] / j) + 1]--;
  44. // cerr << a[i] / j << " ";
  45. }
  46. }
  47. }
  48. // cerr << '\n';
  49. }
  50. // cerr << "\n";
  51. int ans = 1;
  52. for (int i = 1; i <= n; i++) {
  53. ps[i] = ps[i - 1] + ps[i];
  54. if (ps[i] + k >= n) ans = i;
  55. // cerr << ps[i] << " ";
  56. }
  57. // cerr << "\n-------\n";
  58. cout << ans << "\n";
  59. }
  60. signed main() {
  61. cin.tie(NULL)->sync_with_stdio(false);
  62. if(ifstream("Input.inp")) {
  63. freopen("Input.inp", "r", stdin);
  64. freopen("Output.out", "w", stdout);
  65. }
  66. int tt; cin >> tt;
  67. while(tt--) {
  68. solve();
  69. }
  70. return 0;
  71. }
  72.  
  73.  
  74. /*
  75. 15 1 7 10 17 14 17 12 7 4 10 4 15 2 6 2 14 5
  76. 1 0 0 0 1 0 1 1 0 1 0 1 1 0 0 0 0 0
  77.  
  78.  
  79. 4 3 8
  80. */
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
Standard output is empty