Cod sursa(job #2759437)

Utilizator mihnea_buzoiuMihnea Buzoiu mihnea_buzoiu Data 17 iunie 2021 19:10:42
Problema Problema rucsacului Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.49 kb
//
//  problema_rucsacului.cpp
//  probleme
//
//  Created by Mihnea Buzoiu on 6/6/21.
//

#include <stdio.h>
#include <iostream>

const int MAXG = 1e4 + 2;

int best[MAXG];
 
int main()
{
    freopen("rucsac.in", "r", stdin);
    freopen("rucsac.out", "w", stdout);
    
    int n, g;
    scanf("%d %d", &n, &g);
    
    for (int i=0; i<n; i++){
        int w, p;
        scanf("%d %d", &w, &p);
        
        for (int j=g; j>=w; j--)
            best[j] = max(best[j], best[j-w] + p);
    }
}