Pagini recente » Cod sursa (job #2033443) | Cod sursa (job #3270099) | Cod sursa (job #13243) | Cod sursa (job #673636) | Cod sursa (job #1073439)
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <memory.h>
using namespace std;
ifstream fin("energii.in");
ofstream fout("energii.out");
const int Gmax = 1010;
const int Wmax = 15005;
const int oo = 0x3f3f3f3f;
int G, W, E, C, DP[Wmax];
int main()
{
fin>>G>>W;
memset(DP, oo, sizeof DP); DP[0] = 0;
for(int i=1; i <= G; i++)
{
fin>>E>>C;
for(int j=W; j >= 0; j--)
DP[j + E] = min(DP[j + E], DP[j] + C);
}
int minim = oo;
for(int i=W; i < Wmax; i++)
minim = min(minim, DP[i]);
if(minim != oo)
fout<<minim;
else
fout<<"-1";
fin.close();
fout.close();
return 0;
}