There are �n workers and �m tasks. The workers are numbered from 11 to �n. Each task �i has a value ��ai — the index of worker who is proficient in this task.
Every task should have a worker assigned to it. If a worker is proficient in the task, they complete it in 11 hour. Otherwise, it takes them 22 hours.
The workers work in parallel, independently of each other. Each worker can only work on one task at once.
Assign the workers to all tasks in such a way that the tasks are completed as early as possible. The work starts at time 00. What's the minimum time all tasks can be completed by?
Input
The first line contains a single integer �t (1≤�≤1041≤t≤104) — the number of testcases.
The first line of each testcase contains two integers �n and �m (1≤�≤�≤2⋅1051≤n≤m≤2⋅105) — the number of workers and the number of tasks.
The second line contains �m integers �1,�2,…,��a1,a2,…,am (1≤��≤�1≤ai≤n) — the index of the worker proficient in the �i-th task.
The sum of �m over all testcases doesn't exceed 2⋅1052⋅105.
Output
For each testcase, print a single integer — the minimum time all tasks can be completed by.
#include<bits/stdc++.h>
using namespace std;
#define Acode ios::sync_with_stdio(false), cin.tie(0),cout.tie(0)
typedef long long ll;
#define endl '\n'
const int inf = 0x3f3f3f3f;
map<int, int>mp;
int n, m;
bool check(int mid)
{
ll cnt = 0;
for (int i = 1; i <= n; i++)
{
if (mp[i] <= mid) cnt -= (mid - mp[i]) / 2;
else cnt += (mp[i] - mid);
}
if (cnt > 0) return false;
else return true;
}
int main()
{
Acode;
int t;
cin >> t;
while (t--)
{
mp.clear();
cin >> n >> m;
while (m--)
{
int x;
cin >> x;
mp[x]++;
}
int l = 0, r = inf;
while (l <= r)
{
int mid = l + r >> 1;
if (check(mid)) r = mid - 1;
else l = mid + 1;
}
cout << l << endl;
}
return 0;
}