首页 > 其他分享 >E - Gluttony

E - Gluttony

时间:2024-08-11 16:27:31浏览次数:6  
标签:Gluttony 200005 int res st low now

原题链接

题解

1.题目要求我们最小化吃完食物时间的最大值,这给了我们一种二分的感觉。

2.假如给定最大值为 \(K\),那么所有 \(y\) 对应的 \(x\) 都满足 \(x\leq \lfloor \frac{K}{y} \rfloor\)

所以,我们要安排 \(x\),使得每个 \(x\) 达到 \(x\leq \lfloor \frac{K}{y} \rfloor\) 所需的修行尽可能少

所以,我们可以贪心的把大的 \(x\) 分给小的 \(y\)

实施

至此,逆序匹配+二分的思路就有了正确性证明

code

#include<bits/stdc++.h>
using namespace std;
/*
#define double long double
#define lowbit(x) ((x)&(-x))
const int inf=1e18;
const int mod=1e9+7;

const int N=4e5;
int qpow(int a,int n)
{
    int res=1;
    while(n)
    {
        if(n&1) res=res*a%mod;
        a=a*a%mod;
        n>>=1;
    }
    return res;
}
int inv(int x)
{
    return qpow(x,mod-2);
}
int fa[2000005];
int finds(int now){return now==fa[now]?now:finds(fa[now]);}

vector<int> G[200005];

int dfn[200005],low[200005];
int cnt=0,num=0;
int in_st[200005]={0};
stack<int> st;
int belong[200005]={0};

void scc(int now,int fa)
{
    dfn[now]=++cnt;
    low[now]=dfn[now];
    in_st[now]=1;
    st.push(now);

    for(auto next:G[now])
    {
        if(next==fa) continue;

        if(!dfn[next])
        {
            scc(next,now);
            low[now]=min(low[now],low[next]);
        }
        else if(in_st[next])
        {
            low[now]=min(low[now],dfn[next]);
        }
    }

    if(low[now]==dfn[now])
    {
        int x;
        num++;
        do
        {
            x=st.top();
            st.pop();
            in_st[x]=0;
            belong[x]=num;
        }while(x!=now);
    }
}
vector<int> prime;
bool mark[200005]={0};
void shai()
{
    for(int i=2;i<=200000;i++)
    {
        if(!mark[i]) prime.push_back(i);

        for(auto it:prime)
        {
            if(it*i>200000) break;

            mark[it*i]=1;
            if(it%i==0) break;
        }
    }
}
*/
#define int long long

int a[200005],f[200005];
int n,k;
bool check(int x)
{
    int res=0;
    for(int i=1;i<=n;i++)
    {
        if(f[i]*a[i]>x)
        {
            res+=a[i]-(x/f[i]);
        }
    }

    return (res<=k);
}
void solve()
{
    cin>>n>>k;

    for(int i=1;i<=n;i++) cin>>a[i];

    for(int i=1;i<=n;i++) cin>>f[i];

    sort(a+1,a+1+n);
    sort(f+1,f+1+n,greater<int>());

    int l=-1,r=1e12+2;

    while(l+1<r)
    {
        int mid=(l+r)/2;

        if(check(mid)) r=mid;
        else l=mid;
    }

    cout<<r<<'\n';
}
signed main()
{
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int TT=1;
    //cin>>TT;
    while(TT--) solve();
    return 0;
}


标签:Gluttony,200005,int,res,st,low,now
From: https://www.cnblogs.com/pure4knowledge/p/18353569

相关文章

  • Atcoder ABC144E Gluttony
    [ABC144E]Gluttony题面翻译【题目描述】高桥君参加大胃王比赛。比赛由\(N\)人组成的团队为基本单位参赛,高桥君的队伍的队员从\(1\simN\)编号。第\(i\)名队员的消化代价为\(A_i\)。比赛有\(N\)种不同的食物,每位队员需要负责吃掉其中一种食物,不能有两名队员吃同一种......
  • 题解 [ABC144E] Gluttony
    【洛谷博客】题意翻译很清楚,略。分析经过观察最优方案一定是消化代价小的配难消化的菜。所以将\(F\)从小到大排序,\(A\)从大到小排序,当然也可以反着来。因为有\(K\)次修行的机会,难以直接贪心。因为随着时间增加,修行的使用次数会减少,存在单调性。所以考虑使用二分答案转......
  • atcoder beginner contest 144 Gluttony(二分答案)
    题目大意:有an,bn,我们找到an和bn每个元素的一种一一对应关系。使得min(max(ai*bi))。已知我们可以进行操作让an中的任一个元素减少1。操作数最大为k,问我们怎么操作,可以min(......