Pagini recente » Autentificare | Cod sursa (job #2485792) | Cod sursa (job #2221640) | Cod sursa (job #2078313) | Cod sursa (job #1752640)
//
// 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 <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;
// first power, second cost;
vector<pair<int,int>> powers;
int main()
{
fin>>nr_of_gen>>min_power;
for(i=1;i<=nr_of_gen;i++)
{
fin>>power>>cost;
for(auto &el : powers)
{
if( cost_total[el.first + power] == 0 )
cost_total[el.first + power] = MULTFOARTEMULT;
if( cost_total[el.first + power] > el.second + cost )
{
cost_total[el.first + power] = el.second + cost;
if(el.first + power < min_power)
powers.push_back(make_pair(el.first + power, el.second + cost));
}
if( cost_total[el.first + power] == MULTFOARTEMULT )
cost_total[el.first + power] = 0;
}
if( cost_total[power] == 0 )
cost_total[power] = MULTFOARTEMULT;
if( cost_total[power] > cost )
{
cost_total[power] = cost;
if(power < min_power)
powers.push_back(make_pair(power, cost));
}
if( cost_total[power] == MULTFOARTEMULT )
cost_total[power] = 0;
}
Min_cost = MULTFOARTEMULT-1;
for(i=min_power;i<=10000;i++)
{
if(cost_total[i])
{
Min_cost = min(Min_cost, cost_total[i]);
}
}
if(Min_cost!=MULTFOARTEMULT-1)
fout<<Min_cost;
else
fout<<-1;
return 0;
}