其他分享
首页 > 其他分享> > CodeForces-1701C Schedule Management

CodeForces-1701C Schedule Management

作者:互联网

Schedule Management

二分答案

显然答案具备单调性,直接二分,\(check()\) 的时候,优先让工人自己先干自己的活

如果 wa4 记得开 long long(悲

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <functional>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <deque>
#include <stack>
#include <array>
using namespace std;
typedef long long ll;
#define pii pair<int, int>
const ll maxn = 2e5 + 10;
const ll inf = 1e17 + 10;
int n, m;
ll vis[maxn];

bool check(ll x)
{
    ll ans = 0;
    for(int i=1; i<=n; i++)
    {
        if(x > vis[i]) ans += (x - vis[i]) >> 1;
        else ans -= vis[i] - x;
    }
    return ans >= 0;
}

int main()
{
    int t;
    scanf("%d", &t);
    while(t--)
    {
        scanf("%d%d", &n, &m);
        for(int i=0; i<=n; i++) vis[i] = 0;
        for(int i=0; i<m; i++)
        {
            int x;
            scanf("%d", &x);
            vis[x]++;
        }
        ll l = 0, r = m * 2;
        while(l < r)
        {
            ll mid = l + r >> 1;
            if(check(mid)) r = mid;
            else l = mid + 1;
        }
        printf("%lld\n", l);
    }
    return 0;
}

标签:Management,int,1701C,ll,CodeForces,long,vis,ans,include
来源: https://www.cnblogs.com/dgsvygd/p/16462411.html