Cod sursa(job #2552099)
Utilizator | Cuibus Dorin Iosif Dorin07 | Data | 20 februarie 2020 16:13:16 |
---|---|---|---|
Problema | Problema rucsacului | Scor | 0 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.67 kb |
#include <bits/stdc++.h>
#define N 5001
#define X 10001
using namespace std;
ifstream fin("rucsac.in");
ofstream fout("rucsac.out");
int s, p, n, g, a1[X], a2[X], a[X];
void citire(){
cin>>n>>g;
for(int i = 1; i <= n; ++i)
cin>>a1[i]>>a2[i];
}
void alg(){
for(int i = 1; i <= n; ++i){
for(int j=g-a1[i]; j >= 0; j--)
{
if(a[j+a1[i]]< a[j]+a2[i])
{
a[j+a1[i]]=a[j]+a2[i];
if(a[j+a1[i]] > s)
{
s=a[j+a1[i]];
}
}
}
}
}
int main(){
citire();
alg();
cout<<s;
}