Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int dis[601];
- int32_t main(){
- int n,k,sum = 0;
- while(cin >> n >> k){
- ++k;
- for(int i = 0; i <= n; ++i){
- cin >> dis[i];
- sum += dis[i];
- }
- int small = 0, big = sum;
- while(small <= big){
- int mid = (small + big) / 2;
- int days, idx = 0;
- for(days = 0; days <= k && idx <= n; ++days){
- sum = 0;
- while(idx <= n && sum+dis[idx] <= mid){
- sum += dis[idx];
- ++idx;
- }
- }
- if(days <= k)big = mid - 1;
- else small = mid + 1;
- }
- cout << small << '\n';
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement