-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathLOJ-1076.cpp
39 lines (39 loc) · 926 Bytes
/
LOJ-1076.cpp
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include<bits/stdc++.h>
using namespace std;
int main(){
int t;
scanf("%d",&t);
for(int z=1;z<=t;z++){
long long n,m;
scanf("%lld%lld",&n,&m);
long long arr[n],high=0,low=-1;
for(register int i=0;i<n;i++){
scanf("%lld",&arr[i]);
high+=arr[i];
low=max(arr[i],low);
}while((high-low)>=4){
long long mid=(low+high+1)/2,k=1,sum=0;
for(int i=0;i<n;i++){
if((sum+arr[i])<=mid){
sum+=arr[i];
}else{
sum=arr[i];
k++;
}
}
if(k<=m)high=mid;
else low=mid+1;
}for(;low<=high;low++){
long long k=1,sum=0;
for(int i=0;i<n;i++){
if((sum+arr[i])<=low){
sum+=arr[i];
}else{
sum=arr[i];
k++;
}
}if(k<=m)break;
}cout<<"Case "<<z<<": "<<low<<"\n";
}
return 0;
}