Pagini recente » Borderou de evaluare (job #156761) | Cod sursa (job #3245535) | Cod sursa (job #432596) | Cod sursa (job #738720) | Cod sursa (job #2293860)
#include <iostream>
#include <fstream>
using namespace std;
const int NR = 10005 ;
ifstream f ("rucsac.in") ;
ofstream g ("rucsac.out") ;
int t [ 2 ][ NR ] ;
int maxim ;
int main() {
int n , G ; f >> n >> G ;
while ( n -- )
{
int x , y ; f >> x >> y ;
for ( int j = 1 ; j <= G ; j ++ )
{
if ( j < x ) t [ n % 2 ][ j ] = t [ ( n + 1 ) % 2 ][ j ] ;
else
{
t [ n % 2 ][ j ] = max ( t [ ( n + 1 ) % 2 ][ j ] , t [ ( n + 1 ) % 2 ][ j - x ] + y ) ;
}
}
}
g << t [ 0 ][ G ] ;
return 0;
}