Cod sursa(job #2615881)

Utilizator andreic06Andrei Calota andreic06 Data 15 mai 2020 18:59:09
Problema Energii Scor 5
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.73 kb
#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;
}