PTRANG - Phân Trang
Tác giả: khuc_tuan
Ngôn ngữ: Java
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int L = sc.nextInt();
int[] a = new int[n];
for (int i = 0; i < n; ++i)
a[i] = sc.nextInt();
int[] f = new int[n];
for (int i = 0; i < n; ++i) {
f[i] = Integer.MAX_VALUE;
for (int j = i, s = 0; j >= 0; --j) {
s += a[j];
if (s > L)
break;
f[i] = Math.min(f[i], Math.max(L - s, j == 0 ? 0 : f[j - 1]));
}
}
System.out.println(f[n - 1]);
}
}