Pagini recente » Cod sursa (job #934051) | Cod sursa (job #1873319) | Cod sursa (job #2675807) | Cod sursa (job #3227720) | Cod sursa (job #2615881)
#include <iostream>
#include <fstream>
using namespace std;
const int MAX_CENTRALA = 5e3;
const int MAX_X = 1e4;
const int MAX_COST = MAX_CENTRALA + MAX_X;
const int MAX_N = 1e3;
int dp[MAX_COST+1];
ifstream fin ( "energii.in" );
ofstream fout ( "energii.out" );
int profit[MAX_N+1], cost[MAX_N+1];
int main()
{
int n, total, price;
fin >> n >> total;
for ( int i = 1; i <= n; i ++ )
fin >> profit[i] >> cost[i];
for ( price = 0; price <= MAX_COST; price ++ )
for ( int i = 1; i <= n; i ++ )
if ( price - cost[i] >= 0 )
dp[price] = max ( dp[price], dp[price-cost[i]] + profit[i] );
for ( price = 0; price <= MAX_COST && dp[price] < total; price ++ );
fout << price;
return 0;
}