ycy1124 @ 2024-03-23 10:51:14
#include<bits/stdc++.h>
using namespace std;
int a[100001];
int main()
{
int n,m;
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>a[i];
a[i]+=a[i-1];
}
int l=1,ans,r=a[n],mid;
while(l<=r)
{
mid=(l+r)/2;
int js1=0,js2=1;
int i=1;
while(i<=n)
{
if(a[i]-js1>mid)
{
js2++;
js1=a[i-1];
}
i++;
}
if(js2>=m)
{
l=mid+1;
ans=mid;
}
else
{
r=mid-1;
}
}
cout<<ans;
return 0;
}
by IceKylin @ 2024-03-23 11:09:20
@ycy1124
#include<bits/stdc++.h>
using namespace std;
int a[100001];
int main()
{
int n,m;
cin>>n>>m;
for(int i=1;i<=n;i++)
{
cin>>a[i];
a[i]+=a[i-1];
}
int l=1,ans,r=a[n],mid;
while(l<=r)
{
mid=(l+r)/2;
int js1=0,js2=0;
int i=1;
while(i<=n)
{
if(a[i]-js1>=mid)
{
js2++;
js1=a[i-1];
}
i++;
}
if(js2>=m)
{
l=mid+1;
ans=mid;
}
else
{
r=mid-1;
}
}
cout<<ans;
return 0;
}
by ycy1124 @ 2024-03-23 11:29:21
@IceKylin
大佬已关,能不能再帮忙看一下样例四