Cod sursa(job #3280802)

Utilizator Manolea_Teodor_StefanManolea Teodor Stefan Manolea_Teodor_Stefan Data 27 februarie 2025 15:58:03
Problema Energii Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.89 kb
#include <bits/stdc++.h>
//#pragma GCC optimize("O3,unroll-loops")
//#pragma GCC target("avx2,bmi,bmi2,popcnt,lzcnt")


using namespace std;

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

using dbl = double;
using ll = long long;
using ull = unsigned long long;

const int nmax = 1e5 + 1;
const int mod = 1e9 + 7;

int n,w;
vector<pair<int,int>> e;
ll s;
vector<ll> dp(10000001,INT_MAX);
int main() {
    fin >> n >> w;
    e.resize(n);
    for (auto& p : e) {
        fin >> p.first >> p.second;
        s += p.first;
    }
    dp[0] = 0;
    ll ans = INT_MAX;
    for (auto p : e) {
        const int x = p.first, y = p.second;
        for (int i = s; i >= 0; i--) {
            if (i + x <= s) {
                dp[i + x] = min(dp[i + x], dp[i] + y);
                if (i + x >= w)
                    ans = min(dp[i + x], ans);
            }
        }
    }
    fout << ans;

    return 0;
}