数组n个值切割成m段,保证m段中和值最小
[牛客网]shopee的零食柜
题目链接如下:https://www.nowcoder.com/questionTerminal/24a1bb82b3784f86babec24e4a5c93e0?orderByHotValue=1&page=1&onlyReference=false
上代码
#include<iostream>
#include<vector>
using namespace std;
void getMaxPacePerMinute(long n, long m, long bottom, long ceil, vector<long> &musics) {
int maxPace = 0;
while (bottom <= ceil) {
maxPace = bottom + ((ceil - bottom) >> 1);
//cout << "maxpace:" << maxPace <<" " <<bottom <<" " << ceil << endl;
auto num = 0;
for(auto i = 0; i < n;) {
auto sum = 0;
while(i < n && (sum + musics[i] <= maxPace)) {
sum += musics[i++];
}
num++;
if (num