Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include <iostream>
- #include <bitset>
- #include <vector>
- #include <algorithm>
- #include <map>
- #include <set>
- #include <cassert>
- const int N = 2e5 + 7;
- using namespace std;
- int n,m, a[N],b[N], x;
- set<int> s;
- bool check(long long val) {
- long long cnt_add = 0;
- for (int i = 1; i <= n; i++) {
- a[i] = 0;
- }
- for (int i = 0; i < m; i++) {
- if (a[b[i]] + 1 <= val) {
- a[b[i]]++;
- }
- else {
- cnt_add++;
- }
- }
- for (int i = 1; i <= n; i++) {
- cnt_add -= (val - a[i]) / 2;
- }
- return cnt_add <= 0;
- }
- void solve() {
- cin >> n >> m;
- for (int i = 0; i < m; i++) {
- cin >> b[i];
- }
- long long L = 0, R =n * 2 + 1;
- while (R - L > 1) {
- long long mid = (L + R) / 2;
- if (check(mid)) {
- R = mid;
- }
- else {
- L = mid;
- }
- }
- cout << R << "\n";
- }
- int main()
- {
- #ifdef _DEBUG
- freopen("input.txt", "r", stdin);
- #else
- std::ios::sync_with_stdio(false);
- cin.tie(0);
- #endif
- int t;
- cin >> t;
- while (t--) {
- solve();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement