Pagini recente » Cod sursa (job #1827547) | Cod sursa (job #1607022) | Cod sursa (job #1612910) | Cod sursa (job #429211) | Cod sursa (job #1752752)
//
// 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<<30)-1
using namespace std;
ifstream fin("energii.in");
ofstream fout("energii.out");
int i,j,nr_of_gen, min_power, power, cost, cost_total[10001], Min_cost;
bool vizitari[10001];
int main()
{
fin >> nr_of_gen >> min_power;
for(i=1;i<=nr_of_gen;i++)
{
fin >> power >> cost;
for(j = min_power; j > 0; j--)
{
if(vizitari[j])
{
if(cost_total[j + power]==0 || cost_total[j + power] > cost_total[j] + cost)
{
cost_total[j + power] = cost_total[j] + cost;
vizitari[j+power] = true;
}
}
}
if(cost_total[power] == 0 || cost_total[power] > cost)
{
cost_total[power] = cost;
vizitari[power] = i;
}
}
Min_cost = MULTFOARTEMULT;
for(i=min_power;i<=10001;i++)
{
if(cost_total[i])
{
Min_cost = min(Min_cost, cost_total[i]);
}
}
if(Min_cost != MULTFOARTEMULT)
fout << Min_cost;
else
fout << -1;
return 0;
}