Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorithm>
- #include <cstdio>
- using namespace std ;
- #define MaxN 1000
- #define MaxLoad 3000
- #define MaxWeight 3000
- int main() {
- #ifndef ONLINE_JUDGE
- freopen("input.txt", "r", stdin);
- #endif
- int boxs[ MaxLoad + MaxWeight + 1 ] = { 0 } ;
- int weight[ MaxN ] = { 0 } ;
- int load[ MaxN ] = { 0 } ;
- int n = 0 ;
- while( cin >> n && n != 0 ) {
- for(int i = 0 ; i < n ; i++ ) {
- cin >> weight[i] >> load[i];
- }
- fill( boxs, boxs + MaxLoad + MaxWeight + 1, 0 ) ;
- for(int i = n - 1 ; i >= 0 ; i-- ) {
- for(int j = load[ i ] ; j >= 0 ; j-- ) {
- if( boxs[ j ] > 0 ) {
- boxs[ j + weight[i] ] = max(boxs[ j + weight[i] ], boxs[j] + 1);
- }
- }
- boxs[ weight[ i ] ] = max( boxs[ weight[i] ], 1) ;
- }
- cout << *( max_element(boxs, boxs + MaxLoad + MaxWeight + 1) ) << endl ;
- }
- return 0 ;
- }
Advertisement
Add Comment
Please, Sign In to add comment