Cod sursa(job #2143138)

Utilizator AlexandruLuchianov1Alex Luchianov AlexandruLuchianov1 Data 25 februarie 2018 16:55:30
Problema Energii Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.59 kb
#include <iostream>
#include <fstream>

using namespace std;

ifstream in ("energii.in");
ofstream out ("energii.out");

#define MIN(a , b) ((a < b) ? a : b)
int const nmax = 5001;
int const inf = 1000000000;
int dp[5 + nmax];

int main()
{
  int n , k;
  in>>n>>k;
  for(int i = 1 ; i <= nmax ;i++)
    dp[i] = inf;
  dp[0] = 0;
  for(int i = 1 ; i <= n ;i++){
    int a , b;
    in>>a>>b;
    for(int j = k; 0 <= j ;j--){
      dp[MIN(j + a , k)] = MIN(dp[MIN(j + a , k)] , dp[j] + b);
    }
  }
  if(dp[k] == inf)
    out<<-1;
  else
    out<<dp[k];
  return 0;
}