Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int a[6005], f[6005];
- int main() {
- int n, l; cin >> n >> l;
- for (int i = 1; i <= n; i++) {
- cin >> a[i];
- a[i] += a[i - 1];
- }
- memset(f, 0x3f, sizeof(f)); f[0] = 0;
- for (int i = 1; i <= n; i++) {
- int j = i;
- while (j && a[i] - a[j - 1] <= l) {
- f[i] = min(f[i], max(l - a[i] + a[j - 1], f[j - 1]));
- j--;
- }
- }
- cout << f[n] << '\n';
- }
Add Comment
Please, Sign In to add comment