Cod sursa(job #3298401)

Utilizator popuPop Matei Tudor popu Data 29 mai 2025 14:34:25
Problema Problema rucsacului Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.87 kb
#include <bits/stdc++.h>

#define int long long
#define fi first
#define se second

#define sz(a) int((a).size())
#define all(a) (a).begin(), (a).end()

#define lsb(x) (x & (-x))
#define vi vector<int>
#define YES { cout << "YES" << endl; return; }
#define NO { cout << "NO" << endl; return; }

using ll = long long;
using pii = std::pair<int, int>;

using namespace std;

ifstream fin ("rucsac.in");
ofstream fout ("rucsac.out");

void solve_testcase() {
    int n, G;
    fin >> n >> G;
    vector<int>dp(G + 5, 0);
    for (int i = 0, w, f; i < n; ++i) {
        fin >> w >> f;
        for (int j = G; j >= w; --j)
            dp[j] = max(dp[j], dp[j - w] + f);
    }
    fout << dp[G] << "\n";
}

signed main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    int t = 1;
    // cin >> t;
    while (t--)
        solve_testcase();
    return 0;
}