Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- bool check(long long mid, vector<int> &v, int m)
- {
- int c = 1;
- long long sm = 0;
- for (int i = 0; i < v.size(); i++)
- {
- sm += 1LL * v[i];
- if (sm > mid)
- {
- sm = v[i];
- c++;
- }
- }
- return c <= m;
- }
- long getminmaxloadtime(int n, vector<int> &b)
- {
- long long m = n;
- n = b.size();
- long long sm = 0;
- int mx = 0;
- for (auto i : b)
- {
- sm += 1LL*i;
- mx = max(mx, i);
- }
- long long l = mx, r = sm;
- long long ans = r;
- while (l <= r)
- {
- long long mid = (l + r) / 2;
- if (check(mid, b, m))
- {
- ans = mid;
- r = mid - 1;
- }
- else
- l = mid + 1;
- }
- return ans;
- }
Add Comment
Please, Sign In to add comment