제출 #1102551

#제출 시각아이디문제언어결과실행 시간메모리
1102551ndanKnapsack (NOI18_knapsack)C++14
29 / 100
1 ms424 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef vector<int> vi; typedef vector<ll> vll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; #define file "test" #define forr(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i) #define ford(i, b, a) for (int i = (b), _a = (a); i >= _a; --i) #define forf(i, a, b) for (int i = (a), _b = (b); i < _b; ++i) #define rep(i, n) for (int i = 0, _n = (n); i < _n; ++i) #define pb push_back #define mp make_pair #define fi first #define se second #define all(x) x.begin(), x.end() const int maxn = 2e3 + 10; const int MOD = 1e9 + 7; const ll inf = 1e18; const int oo = 1e9 + 7; const float eps = 1e-6; ll n, s, v[maxn], w[maxn], k[maxn]; namespace sub1 { bool check() { return n == 1; } void solve() { cout << v[1] * min(s / w[1], k[1]); } } namespace sub2 { bool check() { if (n <= 100) { bool kt = 1; forr(i, 1, n) if (k[i] != 1) { kt = 0; break; } return kt; } return 0; } void solve() { ll dp[2005]; memset(dp, 0, sizeof dp); forr(i, 1, n) ford(j, s, w[i]) dp[j] = max(dp[j], dp[j - w[i]] + v[i]); cout << dp[s]; } } namespace sub3 { bool check() { if (n <= 100) { bool kt = 1; forr(i, 1, n) if (k[i] > 10) { kt = 0; break; } return kt; } return 0; } void solve() { } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); //freopen(file".in", "r", stdin); //freopen(file".out", "w", stdout); cin >> s >> n; forr(i, 1, n) cin >> v[i] >> w[i] >> k[i]; if (sub1::check()) return sub1::solve(), 0; if (sub2::check()) return sub2::solve(), 0; if (sub3::check()) return sub3::solve(), 0; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...