# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
908875 | tiwerlol | Knapsack (NOI18_knapsack) | C++17 | 79 ms | 35208 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.
#include <bits/stdc++.h>
using namespace std;
ofstream fout("feast.out");
ifstream fin("feast.in");
#define miauDebug
#ifdef miauDebug
#define mau(x) MIAUMIAU(#x, x)
#else
#define mau(x)
#endif
void MIAUMIAU(const char* var_name, auto var_value) {
cout << var_name << " = " << var_value << endl;
}
using ll = long long;
const int nM = 1e3+12;
const ll MOD =
1000000007;
ll dp[2001][2001];
void solve() {
int s, n; cin >> s >> n;
map<int, vector<pair<int, int>>> v;
for(int z = 0; z < n; z++)
{
int val, g, cnt; cin >> val >> g >> cnt;
v[g].push_back(make_pair(val, cnt));
}
int unde = 1;
dp[0][0] = 1;
for(auto &[g, prod] : v)
{
sort(prod.begin(), prod.end(), greater<pair<int, int>>());
for(int i = 0; i <= s; i++)
{
dp[unde][i] = dp[unde-1][i];
ll profit = 0, fol = 0, k = 0, copi = 0, sum = 0;
while((copi + 1)*g <= i && k < prod.size())
{
copi++;
sum += prod[k].first;
dp[unde][i] = max(dp[unde][i], dp[unde-1][i- copi*g] + sum);
fol++;
if(fol==prod[k].second)
{
fol = 0;
k++;
}
}
}
unde++;
}
ll mx = 0;
for(int z = 0; z <= s; z++)
{
mx = max(mx, dp[unde-1][z]);
}
cout << mx-1;
}
signed main()
{
cout.tie(NULL);
cin.tie(NULL);
ios_base::sync_with_stdio(false);
//cin >> p;
int tt = 1;// cin >> tt;
while(tt--)
solve();
}
/*
5
3 1 6 3
iiiii
*/
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... |