Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <cstring>
- #include <algorithm>
- #include <stack>
- #include <fstream>
- #include <map>
- using namespace std;
- int n,m;
- int x[250000];
- int ok(int num)
- {
- vector<int> cnt(n + 5, 0);
- long long problems= 0 ;
- for(int i = 1; i <= m; i++) {
- if(cnt[x[i]] < num) {
- cnt[x[i]]++;
- }
- else {
- problems++;
- }
- }
- for(int i = 1; i <= n; i++) {
- problems -= (num - cnt[i]) / 2;
- if(problems <= 0) return 1;
- }
- return 0;
- }
- int main()
- {
- int t;
- cin>>t;
- while(t--)
- {
- cin>>n>>m;
- for(int i=1;i<=m;i++)
- {
- cin>>x[i];
- }
- int ans=2e9;
- int l=1;
- int r=m * 4;
- int mid=(l+r)/2;
- while(l<=r)
- {
- mid=(l+r)/2;
- if(ok(mid))
- {
- ans=min(ans,mid);
- r=mid-1;
- }
- else
- {
- l=mid+1;
- }
- }
- cout<<ans<<endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement