Cod sursa(job #2041385)

Utilizator butasebiButa Gabriel-Sebastian butasebi Data 17 octombrie 2017 10:32:11
Problema Energii Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.58 kb
#include<bits/stdc++.h>
using namespace std;
int n, E, i, j, v[5015], x, y;
int main()
{
    ifstream f("energii.in");
    ofstream g("energii.out");
    f >> n >> E;
    for(i = 1;i <= E;i++)
        v[i] = 1000000000;
    for(i = 1;i <= n;i++)
    {
        f >> x >> y;
        for(j = E;j >= 0;j--)
        {
            if(j + x < E)
            {
                if(v[j + x] > v[j] + y)v[j + x] = v[j] + y;
            }
            else if(v[E] > v[j] + y)v[E] = v[j] + y;
        }
    }
    if(v[E] == 1000000000)g << "-1";
    else g << v[E];
    return 0;
}