提交时间:2024-05-27 13:21:59
运行 ID: 149447
#include <bits/stdc++.h> using namespace std; int w [10005] , l [10005] , f [10005] , sum [10005] ; int n , t , sw ; int opt ( int l1 , int r1 ) { int w = 0 , h = 0 ; for ( int i = l1 ; i <= r1 ; i ++ ) { h = max ( l [i] , h ) ; } return sum [r1] - sum [l1 - 1] > sw ? 0x3f3f3f3f : h ; } int main ( ) { cin >> n >> sw ; for ( int i = 1 ; i <= n ; i ++ ) { cin >> w [i] >> l [i] ; sum [i] = sum [i - 1] + w [i] ; } for ( int i = 1 ; i <= n ; i ++ ) { f [i] = 0x3f3f3f3f ; for ( int j = i - 1 ; j >= 0 ; j -- ) { if ( opt ( j + 1 , i ) > sw ) { break ; } f [i] = min ( f [i] , f [j] + opt ( j + 1 , i ) ) ; } } cout << f [n] << endl ; return 0 ; }