Pagini recente » Cod sursa (job #2643418) | Cod sursa (job #1105574) | Cod sursa (job #2238471) | Cod sursa (job #274932) | Cod sursa (job #1128564)
#include <fstream>
#define DEBUG 0
#if DEBUG
#include <iostream>
#include <iomanip>
#endif
using namespace std;
int a[5001];
int main()
{
ifstream in("energii.in");
ofstream out("energii.out");
int n, total;
in >> n >> total;
int g, p;
in >> g >> p;
for (int j=g; j>0; --j)
{
a[j] = p;
}
for (int i=total; i>g; --i)
{
a[i] = 10001;
}
for (int i=0; i<n-1; ++i)
{
in >> g >> p;
if (g < total)
{
int s = (g>=total/2) ? total-g : g;
for (int j=1; j<=s; ++j)
{
if (a[j]+p < a[j+g])
{
a[j+g] = a[j] + p;
}
}
}
for (int j=g; j>=1; --j)
{
if (a[j]>p)
{
a[j] = p;
}
}
#if DEBUG
for (int j=1; j<=total; ++j)
{
cout << setw(5) << j << " ";
}
cout << " #" << g << " " << p << "\n";
for (int j=1; j<=total; ++j)
{
cout << setw(5) << a[j] << " ";
}
cout << "\n\n";
#endif
}
#if DEBUG
cout << a[total] << "\n";
#endif
out << a[total];
}