Cod sursa(job #3154046)

Utilizator MegaCoderMinoiu Teodor Mihai MegaCoder Data 2 octombrie 2023 21:20:47
Problema Energii Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.69 kb
#include<fstream>
std::ifstream fin("energii.in");
std::ofstream fout("energii.out");
#define inf 10000000
int dp[10005], g, w;
void fill()
{
    for(int index=1; index<=10004; ++index)
        dp[index]=inf;
}
void read()
{
    fin>>g>>w;
    for(int index=0; index<g; ++index)
    {
        int energy, cost;
        fin>>energy>>cost;
        for(int next=10004; next>=energy; --next)
            dp[next]=std::min(dp[next], dp[next-energy]+cost);
    }
}
void getAns()
{
    int ans=inf+1;
    for(int index=10004; index>=w; --index)
        ans=std::min(ans, dp[index]);
    if(ans==inf)
        fout<<"-1";
    else
        fout<<ans;
}
int main()
{
    fill();
    read();
    getAns();
    return 0;
}