测评会员优惠活动进行中 · 开通 VIP,有效期内测评不限次 VIP 优惠中 · 测评不限次 立即查看

A23559. #include<iostream> #include<cstdio> using namespace std; #define maxn 100005 int n,m,a[maxn]; bool check(int x) { int cnt=0,t=0; for(int i=1;i<=n;i++) { if(cnt+a[i]>=x) t++,cnt=0; cnt+=a[i]; if(t>m) …

单选题 较易

题目描述

#include<iostream>
#include<cstdio>
using namespace std;
#define maxn 100005
int n,m,a[maxn];
bool check(int x)
{
    int cnt=0,t=0;
    for(int i=1;i<=n;i++)
    {
        if(cnt+a[i]>=x) t++,cnt=0;
        cnt+=a[i];
        if(t>m) return false;
    }
    return t<m;
}
int main()
{
    scanf("%d %d",&n,&m);
    int maxx=0,sum=0;
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&a[i]); maxx=max(maxx,a[i]); sum+=a[i];
    }
    int l=maxx,r=sum;
    while(l<=r-2)
    {
        int mid=(l+r)/2;
        if(check(mid)) r=mid;
        else l=mid;
    }
    printf("%d",l);
    return 0;
}

数组a最大的数组下标是(    )。

选项(单选)

上一题 下一题