Advertisement
Josif_tepe

Untitled

Jul 10th, 2022
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <cstring>
  4. #include <algorithm>
  5. #include <stack>
  6. #include <fstream>
  7. #include <map>
  8. using namespace std;
  9.  
  10. int n,m;
  11. int x[250000];
  12.  
  13. int ok(int num)
  14. {
  15. vector<int> cnt(n + 5, 0);
  16. long long problems= 0 ;
  17. for(int i = 1; i <= m; i++) {
  18. if(cnt[x[i]] < num) {
  19. cnt[x[i]]++;
  20. }
  21. else {
  22. problems++;
  23. }
  24. }
  25. for(int i = 1; i <= n; i++) {
  26. problems -= (num - cnt[i]) / 2;
  27. if(problems <= 0) return 1;
  28.  
  29. }
  30. return 0;
  31. }
  32.  
  33. int main()
  34. {
  35. int t;
  36. cin>>t;
  37. while(t--)
  38. {
  39. cin>>n>>m;
  40. for(int i=1;i<=m;i++)
  41. {
  42. cin>>x[i];
  43. }
  44. int ans=2e9;
  45. int l=1;
  46. int r=m * 4;
  47. int mid=(l+r)/2;
  48. while(l<=r)
  49. {
  50. mid=(l+r)/2;
  51. if(ok(mid))
  52. {
  53. ans=min(ans,mid);
  54. r=mid-1;
  55. }
  56. else
  57. {
  58. l=mid+1;
  59. }
  60. }
  61. cout<<ans<<endl;
  62. }
  63. return 0;
  64. }
  65.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement