1 solutions

  • 0
    @ 2022-12-3 12:05:40
    #include<iostream>
    using namespace std;
    typedef long long ll;
    const int N = 1e5+5;
    ll a[N];
    int n,k; 
    bool check(ll x)
    {
    	ll t=0,day=1;
    	for(int i=0;i<n;i++)
    	{
    		if(t+a[i]>x) t=0,day++;
    		t+=a[i];
    	}
    	return day <= k;
    }
    int main()
    {
    	ll l=0,r=0,ans;
    	cin>>n>>k;
    	for(int i=0;i<n;i++)
    	{
    		cin>>a[i];
    		a[i]*=a[i];
    		r+=a[i];
    		l=max(l,a[i]);
    	}
    	while(l<=r)
    	{
    		ll mid=(l+r)/2;
    		if(check(mid)) ans=mid,r=mid-1;
    		else l=mid+1;
    		
    	}
    	cout<<ans;
    	return 0;
    }
    
    • 1

    Information

    ID
    6670
    Time
    1000ms
    Memory
    256MiB
    Difficulty
    7
    Tags
    # Submissions
    41
    Accepted
    11
    Uploaded By