Cod sursa(job #3373610)

Utilizator skeptekal69Andrei Mihai Ionut skeptekal69 Data 7 noiembrie 2026 12:55:00
Problema Energii Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.84 kb
#include <iostream>
#include <fstream>
#include <algorithm>


using namespace std;

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

const int GMAX=1000;

int dp[GMAX+1];

int main()
{
    int n,c,k,g,cost,minim;
    fin>>n>>k;
    int maxk=0;
    for(int i=1; i<=n;i++)
    {

        fin>> g>>cost;
        for(int j=maxk;j>=0;j--)
        {
            if(dp[j]>0 && dp[j]+cost<dp[j+g] || dp[j+k]==0)
                dp[j+g]= dp[j]+cost;


        }
        if(dp[g]>cost)
            dp[g]=cost;
        maxk = min(maxk+g,k);


    }
    //for(int j=0;j<=k+2;j++)
      //  cout<<dp[j]<<" ";
    //cout<<endl;
    if(dp[k]==0)
            dp[k]=-1;
    fout<<dp[k]<<endl;

    return 0;
    //minim= dp[k];
    //for(int j=0; j<=k;j++)
    //{
      //  if(dp[j]<minim && j>=k )
      //  minim=dp[j];
    //}
    //cout<<minim;

    //return 0;
}