Pagini recente » Cod sursa (job #2711546) | Cod sursa (job #1125882) | Cod sursa (job #2465134) | Clasament tabaraichb | Cod sursa (job #2917163)
// This program was written by Mircea Rebengiuc
// on 03.08.2022
// for problem rucsac
#include <stdio.h>
#include <ctype.h>
#define MAXG 10000
FILE *fin, *fout;
static inline int fgetint(){
int n = 0, ch;
while( !isdigit( ch = fgetc( fin ) ) );
do
n = n * 10 + ch - '0';
while( isdigit( ch = fgetc( fin ) ) );
return n;
}
static inline int max( int a, int b ){ return a > b ? a : b; }
int dp[1 + MAXG];
int main(){
fin = fopen( "rucsac.in", "r" );
fout = fopen( "rucsac.out", "w" );
int n, g, i;
int w, p;
n = fgetint();
g = fgetint();
for( ; n-- ; ){
w = fgetint();
p = fgetint();
for( i = g ; i >= w ; i-- )
dp[i] = max( dp[i], p + dp[i - w] );
}
p = 0;
for( i = 0 ; i <= g ; i++ )
p = max( p, dp[i] );
fprintf( fout, "%d\n", p );
fclose( fin );
fclose( fout );
return 0;
}