Cod sursa(job #1005585)

Utilizator StefansebiStefan Sebastian Stefansebi Data 5 octombrie 2013 12:22:31
Problema Energii Scor 85
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.89 kb
#include<fstream>
using namespace std;
ifstream fin("energii.in");
ofstream fout("energii.out");
int optim[1000000], e, c, n, i, j, g, sol, ct;

int main() {
    int mini = 1000000;
    fin >> n; fin >> ct;
    for (i = 1; i <= n; i++){
        fin >> e >> c;
        for (j = ct; j >= 0; j--){
            if (optim[j] != 0){
                if (j + e < ct){
                    if (optim[j + e] > optim[j] + c or optim[j + e] == 0)
                        optim[j + e] = optim[j] + c;
                }
                else{
                    if (mini > optim[j] + c)
                        mini = optim[j] + c;
                }
            }
        }
        if (e >= ct and mini > c)
            mini = c;
        if (optim[e] == 0 or optim[e] > c)
            optim[e] = c;
    }

   // for (i = 1; i <= ct; i++)
   //     fout << optim[i] << " ";
    fout << mini;
}