inthelper(vector<int>& A, int k){ int res = 1, now = 0; for(auto a : A) { if(now + a > k) { now = a; res += 1; } else now += a; } return res; } intSolution::solve(vector<int> &A, int B){ int l = *max_element(begin(A), end(A)), r = INT_MAX, res = INT_MAX; while(l <= r) { int m = l + (r - l) / 2; int d = helper(A,m); if(d <= B) res = min(res, m); if(d > B) l = m + 1; else r = m - 1; } return res; }