标签:air onclick 复杂 选择 define 二分答案 amp display gif
1 #include<bits/stdc++.h> 2 using namespace std; 3 #define N 100005 4 #define ll long long 5 priority_queue<pair<ll,int> >q; 6 int n,m,k,p,h[N],a[N]; 7 ll f[N]; 8 ll calc(int k){ 9 if (f[k]/a[k]<m)return f[k]/a[k]; 10 if (f[k]-1LL*m*a[k]<h[k])return m; 11 return m+1; 12 } 13 bool pd(ll s){ 14 for(int i=1;i<=n;i++)f[i]=s; 15 while (!q.empty())q.pop(); 16 for(int i=1;i<=n;i++)q.push(make_pair(-calc(i),i)); 17 for(int i=1;i<=m;i++){ 18 for(int j=1;j<=k;j++){ 19 int x=q.top().second; 20 q.pop(); 21 f[x]+=p; 22 q.push(make_pair(-calc(x),x)); 23 } 24 if (-q.top().first<=i)return 0; 25 } 26 return (-q.top().first>m); 27 } 28 int main(){ 29 scanf("%d%d%d%d",&n,&m,&k,&p); 30 for(int i=1;i<=n;i++)scanf("%d%d",&h[i],&a[i]); 31 ll l=0,r=1e13; 32 for(int i=1;i<=n;i++)l=max(l,1LL*a[i]); 33 while (l<r){ 34 ll mid=(l+r>>1); 35 if (pd(mid))r=mid; 36 else l=mid+1; 37 } 38 printf("%lld",l); 39 }
[cf505E]Mr. Kitayuta vs. Bamboos
标签:air onclick 复杂 选择 define 二分答案 amp display gif
原文地址:https://www.cnblogs.com/PYWBKTDA/p/13563137.html