# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1123899 | wrtt | Knapsack (NOI18_knapsack) | C++20 | 2 ms | 1864 KiB |
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define pb emplace_back
#define mx(a, b) ((a) > (b) ? (a) : (b))
#define mn(a, b) ((a) < (b) ? (a) : (b))
#define graph(n) vector<int> g[(n)+1];
constexpr int mod = 998244353;
constexpr int inf = 1e18;
void frx(std::string name) {
freopen((name + ".in").c_str(), "r", stdin);
freopen((name + ".out").c_str(), "w", stdout);
}
/*
template <typename T, size_t N>
ostream &operator<<(ostream &os, const T (&arr)[N]) {
os << "[";
for(size_t i = 0; i < N; ++i) {
if(i>0) {
os << ", ";
}
os<<arr[i];
}
return os << "]";
}
*/
void solve() {
int s,n;
cin>>s>>n;
int v[n], w[n], k[n];
for(int i = 0; i < n; ++i) {
cin>>v[i]>>w[i]>>k[i];
}
int dp[n+1][s+1];
memset(dp,0,sizeof(dp));
for(int i = 1; i<=n; ++i) {
for(int j = 0; j<=s; ++j) {
dp[i][j] = dp[i-1][j];
if(j>=w[i-1]) {
dp[i][j] = mx(dp[i][j], dp[i-1][j-w[i-1]]+v[i-1]);
}
}
}
cout<<dp[n][s]<<"\n";
}
signed main() {
std::ios_base::sync_with_stdio(false);
//std::cin.tie(nullptr);
//frx("piggyback");
#ifdef LOCAL
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
auto start = std::chrono::high_resolution_clock::now();
#endif
int t = 1;
//cin >> t;
int curr = 1;
while (t--) {
//cout<<"Case "<<curr<<"\n";
++curr;
solve();
}
#ifdef LOCAL
auto end = std::chrono::high_resolution_clock::now();
std::chrono::duration<double> elapsed = end - start;
std::cout << elapsed.count() << " seconds\n";
#endif
return 0;
}
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... |