Cod sursa(job #1752736)

Utilizator ducu34Albastroiu Radu Gabriel ducu34 Data 4 septembrie 2016 23:36:37
Problema Energii Scor 5
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.8 kb
//
//  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>> points;

int main()
{
    fin>>nr_of_gen>>min_power;
    
    for(i=1;i<=nr_of_gen;i++)
    {
        fin>>power>>cost;
        
        for(auto element:points)
        {
            if(cost_total[element.first+power])
            {
                if(element.second+cost < cost_total[element.first+power])
                {
                    cost_total[element.first+power]=element.second+cost;
                    points.push_back(make_pair(element.first+power, element.second+cost));
                }
            }
            else
            {
                cost_total[element.first+power]=element.second+cost;
                points.push_back(make_pair(element.first+power, element.second+cost));
            }
        }
        
        if(cost_total[power])
        {
            if(cost < cost_total[power])
            {
                cost_total[power]=cost;
                points.push_back(make_pair(power, cost));
            }
        }
        else
        {
            cost_total[power]=cost;
            points.push_back(make_pair(power, cost));
        }
    
    }
    
    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;
}