[Offer收割]编程练习赛98 register

Ended

Participants:89

Verdict:Accepted
Score:100 / 100
Submitted:2019-03-31 12:59:10

Lang:G++

Edit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int a,b,A[100001];
bool check(ll x){
    ll w=0;
    int k=0;
    for(int i=1;i<=a;i++){
        w+=A[i];
        if(w>=x)k++,w=0;
    }
    return k>=b;
}
int main() {
    ll w=0,l,r,mid,ans;
    cin>>a>>b;
    for(int i=1; i<=a; i++)scanf("%d",&A[i]),w+=A[i];
    l=1,r=w/b;
    while(l<=r){
        mid=l+r>>1;
        if(check(mid))ans=mid,l=mid+1;
        else r=mid-1;
    }
    cout<<ans;
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX