Cod sursa(job #3228818)
Utilizator | Dobre Radu Fabian dobreradu | Data | 11 mai 2024 14:13:00 |
---|---|---|---|
Problema | Problema rucsacului | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.55 kb |
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ifstream in("rucsac.in");
ofstream out("rucsac.out");
const int GMAX = 1e4 + 5;
int dp[GMAX];
int main()
{
int n, g;
in >> n >> g;
for( int i = 1; i <= n; i++ ){
int wi, pi; in >> wi >> pi;
for( int j = g; j >= wi; j-- ){
if( pi + dp[j - wi] > dp[j] )
dp[j] = pi + dp[j - wi];
}
}
int maxi = 0;
for( int i = 1; i <= g; i++ )
maxi = max( maxi, dp[i]);
out << maxi;
return 0;
}