提交时间:2023-11-15 14:06:54
运行 ID: 110721
#include<bits/stdc++.h> using namespace std; int a[100010], n, m; bool chk(int k){ int now = 0, tot = 0; for(int i = 1 ; i <= n ; i ++){ if(now + a[i] > k){ tot ++; now = 0; if(tot > m)return false; } now += a[i]; } return true; } int main(){ cin >> n >> m; for(int i = 1 ; i <= n ; i ++) cin >> a[i]; int l = 1, r = INT_MAX; while(l < r){ int mid = (l + r) / 2; if(chk(mid)) r = mid; else l = mid + 1; } cout << l << '\n'; }