Cod sursa(job #2357296)

Utilizator Teo_1101Mititelu Teodor Teo_1101 Data 27 februarie 2019 11:39:15
Problema Energii Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.7 kb
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;

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

const int INF = (1 << 30);
int G,W;
int mat[5010];
int x,y;
vector <int> L;
void Read()
{
    fin>>G>>W;
    for(int i=1;i<=5002;++i)
        mat[i]=INF;
    for(int i=1;i<=G;++i)
    {
        fin>>x>>y;
        int l,c;
        for(int k=0;k<L.size();++k)
        {
            l=L[k];
            mat[l+x]=min(mat[l+x],mat[l]+y);
        }
        mat[x]=min(mat[x],y);
        L.push_back(x);
    }
    int cost=INF;
    for(int i=W;i<=5002;++i)
        cost=min(cost,mat[i]);
    fout<<cost;
}
int main()
{
    Read();
    return 0;
}