Pagini recente » Cod sursa (job #1926140) | Cod sursa (job #961586) | Cod sursa (job #3239149) | Cod sursa (job #1608800) | Cod sursa (job #1325157)
#include <fstream>
using namespace std;
ifstream f("energii.in");
ofstream g("energii.out");
struct asd{
int g,p;
}a[10008];
long long d[100008],N,G,i,j,s;
int main()
{
f >> N >> G;
for(i = 1; i <= N; i++){
f >> a[i].p >> a[i].g;
s += a[i].g;
}
for(i = 1; i <= N; i++){
for(j = s; j >= a[i].g; j--){
d[j] = max(d[j],d[j-a[i].g] + a[i].p);
/* if(i == N){
if(d[j] != G && d[j+1] == G){
g << j+1;
return 0;
}
} */
}
}
for(i = 1; i <= s; i++){
if(d[i] >= G ){
g << i;
return 0;
}
}
g << -1;
return 0;
}