Physical Address
304 North Cardinal St.
Dorchester Center, MA 02124
You want to rob a jewellery store. The jewellery store sells nn different types of jewels and for each type it has 109109 identical jewels of that type. A jewel of the ii-th type weighs ii grams and is worth aiai euros.
You plan to steal exactly kk jewels with a total weight of exactly ww grams (you can steal multiple jewels of the same type). What is the maximum possible total value, in euros, of the stolen jewels?
Print the maximum possible total value, in euros, of the stolen jewels if the robbery satisfies the constraints described in the statement.
3 2 4
11 10 8
20
There are 33 types of jewels:
The plan is to steal 22 jewels with a total weight of 44 grams. There are two valid choices of jewels to steal:
3 3 6
10 5 8
23
The plan is to steal 33 jewels with a total weight of 66 grams. There are two valid choices of jewels to steal:
2 1000000 1994294
454353453 941594523
938814325454580
There is only one valid choice of jewels to steal: 57065706 jewels of type 11 and 994294994294 jewels of type 22. In this way, the value of the stolen jewels would be 5706⋅454353453+994294⋅941594523=9388143254545805706⋅454353453+994294⋅941594523=938814325454580.
5 11 40
15 14 14 12 12
146
There are many valid choices of jewels to steal, one of the optimal choices (i.e., one of the choices which achieves the maximum total value of 146146) is: one jewel of type 22, six jewels of type 33, four jewels of type 55.
/**
* author: tourist
* created: 09.01.2022 19:26:59
**/
#undef _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "algo/debug.h"
#else
#define debug(...) 42
#endif
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, k, w;
cin >> n >> k >> w;
vector<long long> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
w -= k;
auto GetL = [&](int v) -> int {
return (int) ((long long) w * v / k - 2 * n);
};
auto GetR = [&](int v) -> int {
return (int) ((long long) w * v / k + 2 * n);
};
const long long inf = (long long) 2e18;
function<vector<long long>(int)> Dfs = [&](int v) {
int L = GetL(v);
int R = GetR(v);
vector<long long> ret(R - L + 1, -inf);
if (v == 1) {
for (int i = L; i <= R; i++) {
ret[i - L] = (i >= 0 && i < n ? a[i] : -inf);
}
return ret;
}
if (v % 2 == 1) {
auto got = Dfs(v - 1);
int LL = GetL(v - 1);
int RR = GetR(v - 1);
for (int x = LL; x <= RR; x++) {
for (int y = 0; y < n; y++) {
int z = x + y;
if (z >= L && z <= R) {
ret[z - L] = max(ret[z - L], got[x - LL] + a[y]);
}
}
}
return ret;
}
auto got = Dfs(v / 2);
int LL = GetL(v / 2);
int RR = GetR(v / 2);
for (int x = LL; x <= RR; x++) {
for (int y = x; y <= RR; y++) {
int z = x + y;
if (z >= L && z <= R) {
ret[z - L] = max(ret[z - L], got[x - LL] + got[y - LL]);
}
}
}
return ret;
};
auto res = Dfs(k);
int L = GetL(k);
int R = GetR(k);
assert(L <= w && w <= R);
cout << res[w - L] << '\n';
return 0;
}
In our experience, we suggest you solve this Scrupulous Robbery Plan CodeChef Solution and gain some new skills from Professionals completely free and we assure you will be worth it.
Scrupulous Robbery Plan Problem is available on Hacker Rank for Free, if you are stuck anywhere between a compilation, just visit Queslers to get Scrupulous Robbery Plan CodeChef Solution.
I hope this Scrupulous Robbery Plan CodeChef Solution would be useful for you to learn something new from this problem. If it helped you then don’t forget to bookmark our site for more Hacker Rank, Leetcode, Codechef, Codeforce Solution.
This Problem is intended for audiences of all experiences who are interested in learning about Data Science in a business context; there are no prerequisites.
Keep Learning!
More CodeChef Solutions >>
Olympics Ranking CodeChef Solution
Problem Difficulties CodeChef Solution
Chef and Bulb Invention CodeChef Solution