# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
941691 | yophis | Knapsack (NOI18_knapsack) | C++17 | 1051 ms | 33980 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <cmath>
#include <cstdio>
#include <map>
#include <stack>
#include <numeric>
#include <queue>
#include <climits>
using namespace std;
using ll = long long;
using str = string;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
#define all(x) begin(x), end(x)
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
const int INF = 1e9;
void setIO(string filename = "") {
ios_base::sync_with_stdio(false); cin.tie(0);
if (filename.size()) {
freopen((filename+".in").c_str(), "r", stdin);
freopen((filename+".out").c_str(), "w", stdout);
}
}
// =====================================
int n,s;
int main() {
setIO();
cin >> s >> n;
vector<pii> v;
FOR (i, 0, n) {
int val, weight, cnt; cin>>val>>weight>>cnt;
FOR (j, 0, cnt) v.pb({val, weight});
}
vl dp(s+1);
for (auto &[val, weight]: v) {
for (int i=s;i>=0;i--) {
ll left = i - weight;
if (left >= 0) {
dp[i] = max(dp[i], dp[left] + val);
}
}
}
cout << dp[s] << '\n';
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |