| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1318894 | mrbet | Knapsack (NOI18_knapsack) | C++20 | 1 ms | 332 KiB |
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define forr(_a,_b,_c) for(int _a = (_b); _a <= int (_c); ++_a)
#define ford(_a,_b,_c) for(int _a = (_b) + 1; _a --> int (_c);)
#define forf(_a,_b,_c) for(int _a = (_b); _a < int (_c); ++_a)
#define pb push_back
#define fi first
#define se second
#define vi vector
#define all(_v) _v.begin(), _v.end()
#define mask(_x) (1ll << (_x))
#define bit(_x,_y) (((_x) >> (_y)) & 1)
#define file "A"
string yes[2] = {"NO\n","YES\n"};
const ld eps = ld(1e-7);
const ll oo = ll(1e16) + 1;
const ll mod = ll(1e9) + 7;
template<class X, class Y>
inline bool Min(X &x, const Y &y) {
if(x > y) {
x = y;
return true;
}
return false;
}
template<class X, class Y>
inline bool Max(X &x, const Y &y) {
if(x < y) {
x = y;
return true;
}
return false;
}
const int N = 1e5+5;
int s,n;
ll dp[N];
pair<int,pii> a[N];
void solve() {
cin>>s>>n;
forr(i,1,n) cin>>a[i].fi>>a[i].se.fi>>a[i].se.se;
forr(i,1,n) {
int k= a[i].se.se;
int v=1;
while (k>=v) {
ford(j,s,a[i].se.fi*v) dp[j]=max(dp[j],dp[j-a[i].se.fi*v]+a[i].fi*v);
k-=v;
v*=2;
}
if (k) ford(j,s,a[i].se.fi*k) dp[j]=max(dp[j],dp[j-a[i].se.fi*k]+a[i].fi*k);
}
cout<<dp[s];
}
void precalc() {
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(0);
cout << fixed << setprecision(7);
if (fopen(file".inp","r")) {
freopen(file".inp","r",stdin); freopen(file".out","w",stdout);
}
int tc = 1;
//cin >> tc;
precalc();
while(tc --> 0) {
solve();
}
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... | ||||
