| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1355147 | bnd2100 | Knapsack (NOI18_knapsack) | C++20 | 8 ms | 2740 KiB |
/*
* @Author: Twynzz
* @Last Modified by: Twynzz
* @Note For This Problem: https://aistudio.google.com/prompts/1-Jr1qoiKenShfOc7xFvDMsuL9aJSw3Xg
*/
#include <bits/stdc++.h>
using namespace std;
char __ST__;
extern char __EN__;
// ------------ Define ------------
#define int long long
#define ll long long
#define ld long double
#define str string
#define file(name) {freopen(name".inp","r",stdin);freopen(name".out","w",stdout);}
#define IOS {std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);}
#define _TBN_ signed main()
#define setp(n) setprecision(n)<< fixed
#define fi first
#define se second
#define ii pair<int,int>
#define gcd(a,b) __gcd(a,b)
#define iii tuple<int, int, int>
#define pb push_back
#define pf push_front
#define eb emplace_back
#define sz(v) (int)v.size()
#define el "\n"
#define all(x) x.begin(),x.end()
const long long oo = 1e18;
const int MOD = 1e9+7, Mod = 998244353;
const int base = 311, base2 = 293;
template<class X>
bool maximize(X &a, const X &b)
{
if (a<b)
{
a = b;
return 1;
}
return 0;
}
template<class X>
bool minimize(X &a, const X &b)
{
if (a>b)
{
a = b;
return 1;
}
return 0;
}
namespace sub1
{
bool checkSub1();
void sub1();
}
namespace sub2
{
bool checkSub2();
void sub2();
}
namespace sub3
{
bool checkSub3();
void sub3();
}
int lcm(int a, int b)
{
return a/gcd(a,b)*b;
}
int sqr(int x) {return x*x;}
inline bool MASK(int mask, int bit) {return ((mask>>bit)&1);}
inline long long F(int n) {return n*(n+1)/2;}
inline int add(int a, int b, int m = MOD)
{
return ((a % m + b % m) % m + m) % m;
}
inline int sub(int a, int b, int m = MOD)
{
return ((a % m - b % m) % m + m) % m;
}
inline int mul(int a, int b, int m = MOD)
{
return (((a % m) * (b % m)) % m + m) % m;
}
int dx[] = {0, 0, -1, 1};
int dy[] = {-1, 1, 0, 0};
const int maxn = 1e6 + 9;
const int N = 1e5 + 9;
// ------------ Code ------------
int n, s, v[maxn], w[maxn], k[maxn];
_TBN_
{
IOS;
if (fopen("post.inp","r")) file("post");
cin >>s >>n;
for(int i = 1; i <= n; i++) cin >>v[i] >>w[i] >>k[i];
for(int i = 1; i <= 1; i++)
{
if (sub1::checkSub1()) {sub1::sub1(); continue;}
if (sub2::checkSub2()) {sub2::sub2(); continue;}
if (sub3::checkSub3()) {sub3::sub3(); continue;}
}
cerr << "\nStatic memory used: " << fixed << setprecision(3) << ((&__EN__ - &__ST__) / (1.0L * 1024 * 1024)) << "mb\n";
return 0;
}
namespace sub1
{
bool checkSub1()
{
return n <= 100;
}
int dp[maxn];
void sub1()
{
for(int j = 0; j <= s; j++)
dp[j] = -oo;
dp[0] = 0;
for(int i = 1; i <= n; i++)
{
int rem = k[i];
for(int p = 1; rem > 0; p <<= 1)
{
int cap = min(p, rem);
int W = w[i] * cap, val = v[i] * cap;
for(int j = s; j >= W; j--)
maximize(dp[j], dp[j - W] + val);
rem -= cap;
}
}
int ans = -oo;
for(int j = 0; j <= s; j++)
maximize(ans, dp[j]);
cout<< ans<< el;
}
}
namespace sub2
{
bool checkSub2()
{
return 1;
}
void sub2()
{
}
}
namespace sub3
{
bool checkSub3()
{
return 1;
}
void sub3()
{
}
}
char __EN__;Compilation message (stderr)
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
