# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
645663 | nayhz | Knapsack (NOI18_knapsack) | C++17 | 51 ms | 1996 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.
// source identifier task_name
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
#define lck cout << "ick bmi 32.9\n"
#define cam_cs cout << "ick orz\n"
#define orz(x) cout << (x) << " orz\n"
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pcc pair<char, char>
#define ll long long
#define ull unsigned long long
#define ld long double
// #define int long long
#define vi vector<int>
#define vll vector<long long>
#define vd vector<double>
#define vpii vector<pair<int, int>>
#define vpll vector<pair<long long, long long>>
#define vc vector<char>
#define vsc vector<string>
#define vb vector<bool>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define yes() cout << "Yes\n"
#define no() cout << "No\n"
#define impossible() cout << "Impossible\n"
template<typename T, typename V>
inline void print (const std::pair<T, V> &x) {std::cout << x.first << ' ' << x.second << '\n';}
template<typename T>
inline void print (const T &x) {std::cout << x << '\n';}
template<typename T>
inline void print (std::vector<T> &x) {for (auto &y : x) std::cout << y << " "; std::cout << '\n';}
inline void print () {std::cout << '\n';}
using namespace std;
const ld pi = acos(-1);
const ld eps = 1e-9;
const ll mod = 1000000007;
const ll inf = 1000000007;
clock_t T, NT;
inline double get_time() {NT = clock() - T; return (double)(NT) / CLOCKS_PER_SEC;}
void file_io (string x);
/*
>>>>>>>>>>>>>>>>>>>>>>>>>>END OF TEMPLATE HEADER<<<<<<<<<<<<<<<<<<<<<<<<
*/
void solve (int &tc) {
int s, n; cin >> s >> n;
vpii a[2005];
for (int i = 1; i <= n; i++) {
int v, w, k; cin >> v >> w >> k;
a[w].pb({v, k});
}
vi dp(2005);
int ans = 0;
for (int i = 1; i <= s; i++) {
sort(all(a[i]), greater<pii>());
int pt = 0;
for (int j = 0; j < s / i; j++) {
if (pt >= (int)(a[i].size())) break;
for (int k = s; k >= i; k--) {
dp[k] = max(dp[k], dp[k - i] + a[i][pt].fi);
ans = max(ans, dp[k]);
}
a[i][pt].se--;
if (a[i][pt].se == 0) pt++;
}
}
print(ans);
}
signed main () {
cin.tie()->sync_with_stdio(false);
T = clock();
srand(time(NULL));
// file_io("");
int t = 1;
// cin >> t;
for (int i = 1; i <= t; i++) {
solve(i);
// if (i != t) cout << '\n';
}
// while (true) {solve(t); t++;}
return 0;
}
void file_io (string x = "x") {
string i = x + ".in";
freopen(i.c_str(), "r", stdin);
string o = x + ".out";
freopen(o.c_str(), "w", stdout);
}
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... |