提交时间:2024-05-25 16:47:40
运行 ID: 149150
# include <bits/stdc++.h> using namespace std ; int l [114514] , w [114514] , sum [114514] , r [114514] , f [114514] , n , 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 ? 1e10 : 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] = 1e10 ; 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 ; }