Untitled
unknown
c_cpp
13 days ago
561 B
2
Indexable
Never
int a[200005],n,k; int chk(int m){ int c=1, s=0; for(int i=0; i<n; ++i){ if (a[i]>m) return 0; if (s+a[i]>m) { c++; s=a[i]; } else s+=a[i]; } return c; } void sol(){ cin >> n >> k; int m=1e18; for(int i=0; i<n; ++i){ cin >> a[i]; } int l=0, r=1e18, mid; while(l<=r){ mid=(l+r)>>1; int cnt=0, mcnt=0; if(chk(mid)<=k){ r=mid-1; m=mid; } else l=mid+1; } cout << m; }
Leave a Comment