Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals), problem: (F) Bamboo Partition Solution In C/C++

#include<cstdio>
#include<algorithm>
using namespace std;
int n,a[110]; long long k,ans=0;
int main(){
scanf(“%d%lld”,&n,&k);
for (int i=1; i<=n; i++) scanf(“%d”,&a[i]);
for (long long l=1,r; l<=1LL<<62; l=r+1){
// printf(“%lld %lld\n”,l,r);
long long cnt=0,weight=0; r=1LL<<62;
for (int i=1; i<=n; i++){
cnt+=(((a[i]-1)/l)+1)*l-a[i];
weight+=(a[i]-1)/l+1;
if ((a[i]>l) && ((a[i]-1)/((a[i]-1)/l) < r)) r=(a[i]-1)/((a[i]-1)/l);
}
// printf(“==%lld %lld %lld %lld\n”,l,r,cnt,weight);
if (k>=cnt){
long long nex=(k-cnt)/weight;
ans=max(ans,min(l+nex,r));
}
}
printf(“%lld\n”,ans);
}

#include<cstdio>
#include<algorithm>
using namespace std;
int n,a[110]; long long k,ans=0;
int main(){
scanf(“%d%lld”,&n,&k);
for (int i=1; i<=n; i++) scanf(“%d”,&a[i]);
for (long long l=1,r; l<=1LL<<62; l=r+1){
// printf(“%lld %lld\n”,l,r);
long long cnt=0,weight=0; r=1LL<<62;
for (int i=1; i<=n; i++){
cnt+=(((a[i]-1)/l)+1)*l-a[i];
weight+=(a[i]-1)/l+1;
if ((a[i]>l) && ((a[i]-1)/((a[i]-1)/l) < r)) r=(a[i]-1)/((a[i]-1)/l);
}
// printf(“==%lld %lld %lld %lld\n”,l,r,cnt,weight);
if (k>=cnt){
long long nex=(k-cnt)/weight;
ans=max(ans,min(l+nex,r));
}
}
printf(“%lld\n”,ans);
}

More from author

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Related posts

Advertismentspot_img

Latest posts

Voltage imaging of neurons distributed across entire brains of larval zebrafish – Nature

In a groundbreaking advancement for neuroscience, researchers have developed an innovative high-speed optical microscopy platform capable of recording electrical activity across the entire brain...

Everything You Need to Know About Viral Kitchen Gadgets Right Now

📢 As an Amazon Associate, I earn from qualifying purchases.There comes a point when you realise that tolerating a frustrating situation is costing you...

Liberal MP’s travel documents show claims he voted on bills while in China are false

Recent online claims accusing Canadian Member of Parliament Shaun Chen of violating parliamentary voting rules have been debunked following the release of travel records...

Want to stay up to date with the latest news?

We would love to hear from you! Please fill in your details and we will stay in touch. It's that simple!