求调
查看原帖
求调
655072
xueba1hao大聪明楼主2024/10/1 10:16
#include <bits/stdc++.h>
using namespace std;

long long l,k,b[100005],ans1=-1,ans2=-1;

int check(int a)
{
  int now1=0,sum=0;
  for(int i=1; i<=l; i++)
  {
    now1+=b[i];
    if(now1<0)
      now1=0;
    //cout<<now1<<" ";
    if(now1>=a)
    {
      sum++;
      now1=0;
    }
    //cout<<now1<<" ";
  }
  //cout<<endl;
  return sum;
}
int main()
{
  cin>>l>>k;
  for(int i=1; i<=l; i++)
    cin>>b[i];
  //for(int i=1; i<=l; i++)
  //cout<<b[i]<<" ";
  //cout<<endl;
  long long L=0,r=1e18;
  while(L<=r)
  {
    long long mid=(L+r)/2;
    if(check(mid)<=k)
    {
      r=mid-1;
      if(check(mid)==k)
        ans1=mid;
    }
    else
      L=mid+1;
  }
  L=0,r=1e18;
  while(L<=r)
  {
    long long mid=(L+r)/2;
    if(check(mid)>=k)
    {
      L=mid+1;
      if(check(mid)==k)
        ans2=mid;
    }
    else
      r=mid-1;
  }
  if(ans1==-1)
    cout<<-1<<endl;
  else
    cout<<ans1<<" "<<ans2<<endl;
  //cout<<endl<<endl;
  //cout<<check(ans1)<<" "<<check(ans2)<<endl;
  return 0;
}

2024/10/1 10:16
加载中...