提交时间:2024-05-25 15:17:35
运行 ID: 148940
#include <bits/stdc++.h> using namespace std; #define MAX 0x3f3f3f3f const int N = 10005; int x[N], y[N], f[N], sum[N]; int n, t, k; int Opt(int L, int R) { int W = 0, h = 0; for (int i = L; i <= R; i++) h = max(y[i], h); return sum[R] - sum[L - 1] > k ? MAX : h; } int main() { cin >> n >> k; for (int i = 1; i <= n; i++){ cin >> x[i] >> y[i]; sum[i] = sum[i - 1] + x[i]; } for (int i = 1; i <= n; i++){ f[i] = MAX; for (int j = i - 1; j >= 0; j--){ if (Opt(j + 1, i) > k) break; f[i] = min(f[i], f[j] + Opt(j + 1, i)); } } cout << f[n]; return 0; }