Pagini recente » Borderou de evaluare (job #2769968) | Argumentatia | Cod sursa (job #863081) | Cod sursa (job #90565) | Cod sursa (job #2652363)
#include<fstream>
#include<iostream>
#include <algorithm>
using namespace std;
ifstream f ("a.in");
ofstream g("a.out");
long long n,gmax,rasp;
long long matr[5001][10001];
int greutati[5001],costuri[5001];
void afla_cale(int x,int y)
{
if(matr[x-1][y] == matr[x][y])
afla_cale(x-1,y);
else
if(matr[x-1][y-greutati[x]] == matr[x][y]-costuri[x])
{
afla_cale(x-1,y-greutati[x]);
cout << x << endl;
}
}
int main()
{
f >> n >> gmax;
for(int i = 1;i<=n;i++)
{
long long gr,cost;
f >> gr>> cost;
greutati[i] = gr;
costuri[i] = cost;
for (int j=1; j<gr; j++)
{
matr[i][j]=matr[i-1][j];
}
for (int j=gr;j<=gmax; j++)
{
matr[i][j] = max(matr[i-1][j], matr[i - 1][j - gr] + cost);
}
}
afla_cale(n,gmax);
}