Pagini recente » Cod sursa (job #2798661) | Cod sursa (job #438862) | Cod sursa (job #1438859) | Cod sursa (job #149472) | Cod sursa (job #2293822)
#include <iostream>
#include <fstream>
using namespace std;
const int NR = 10005 ;
ifstream f ("rucsac.in") ;
ofstream g ("rucsac.out") ;
int t [ 2 ][ NR ] ;
int main() {
int n , G ; f >> n >> G ;
while ( n -- )
{
int x , y ; f >> x >> y ;
for ( int i = 0 ; i + x <= G ; ++ i ) t [ ( n + 2 ) % 2 ][ i + x ] = max ( t [ ( n + 1 ) % 2 ][ i ] + y , t [ ( n + 1 ) % 2 ][ i + x ] ) ;
}
g << t [ 0 ][ G ] ;
return 0;
}