Advertisement
bibaboba12345

Untitled

Jul 8th, 2022
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include <iostream>
  3. #include <bitset>
  4. #include <vector>
  5. #include <algorithm>
  6. #include <map>
  7. #include <set>
  8. #include <cassert>
  9.  
  10. const int N = 2e5 + 7;
  11. using namespace std;
  12. int n,m, a[N],b[N], x;
  13. set<int> s;
  14.  
  15. bool check(long long val) {
  16. long long cnt_add = 0;
  17. for (int i = 1; i <= n; i++) {
  18. a[i] = 0;
  19. }
  20. for (int i = 0; i < m; i++) {
  21. if (a[b[i]] + 1 <= val) {
  22. a[b[i]]++;
  23. }
  24. else {
  25. cnt_add++;
  26. }
  27. }
  28. for (int i = 1; i <= n; i++) {
  29. cnt_add -= (val - a[i]) / 2;
  30. }
  31. return cnt_add <= 0;
  32. }
  33.  
  34. void solve() {
  35. cin >> n >> m;
  36. for (int i = 0; i < m; i++) {
  37. cin >> b[i];
  38. }
  39.  
  40. long long L = 0, R =n * 2 + 1;
  41. while (R - L > 1) {
  42. long long mid = (L + R) / 2;
  43. if (check(mid)) {
  44. R = mid;
  45. }
  46. else {
  47. L = mid;
  48. }
  49. }
  50. cout << R << "\n";
  51. }
  52.  
  53. int main()
  54. {
  55. #ifdef _DEBUG
  56. freopen("input.txt", "r", stdin);
  57. #else
  58. std::ios::sync_with_stdio(false);
  59. cin.tie(0);
  60. #endif
  61. int t;
  62. cin >> t;
  63. while (t--) {
  64. solve();
  65. }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement