Pagini recente » Cod sursa (job #1202723) | Cod sursa (job #2636393) | Cod sursa (job #2975513) | Cod sursa (job #2705004) | Cod sursa (job #1752759)
//
// main.cpp
// Energii
//
// Created by Albastroiu Radu on 9/4/16.
// Copyright © 2016 Albastroiu Radu. All rights reserved.
//
#include <iostream>
#include <fstream>
#include <algorithm>
#include <unordered_map>
#include <vector>
#define MULTFOARTEMULT (1<<28)-1
using namespace std;
ifstream fin("energii.in");
ofstream fout("energii.out");
int i,j,nr_of_gen, min_power, power, cost, cost_total[11001], Min_cost;
int main()
{
fin >> nr_of_gen >> min_power;
for(i=1;i<=10001;i++)
cost_total[i]=MULTFOARTEMULT;
Min_cost = MULTFOARTEMULT;
for(i=1;i<=nr_of_gen;i++)
{
fin >> power >> cost;
for(j=min_power-1;j>=0;j--)
{
cost_total[j + power] = min(cost_total[j + power], cost_total[j] + cost);
if(j+power >= min_power)
{
Min_cost = min(Min_cost, cost_total[j+power]);
}
}
cost_total[power]=min(cost_total[power],cost);
if(power>min_power)
{
Min_cost = min(Min_cost, cost);
}
}
if(Min_cost!=MULTFOARTEMULT)
fout<<Min_cost;
else
fout<<-1;
return 0;
}