Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- using ll = long long;
- #define endl '\n'
- const int N = 3e3 + 10;
- const int sz = 10;
- const double eps = 1e-3;
- const int INF = 0x3f3f3f3f;
- int v[sz];
- int n, m;
- struct str {
- int a, b;
- double val;
- } stone[N];
- void init () {
- for (int i = 0; i < sz; i ++) {
- cin >> v[i];
- }
- cin >> n >> m;
- for (int i = 1; i <= n; i ++) {
- int a, b;
- double c;
- cin >> a >> b;
- c = (double)b / double(a);
- stone[i] = {a, b, c};
- }
- }
- vector<pair<int, int>> vec;
- void pre () {
- vec.clear();
- for (int i = 1; i <= n; i ++) {
- auto [a, b, val] = stone[i];
- for (int i = 0; i < 13; i ++) {
- int cura = a << i, curb = b << i;
- if (cura > m || curb > m) break;
- vec.push_back({cura, curb});
- }
- }
- }
- int dp[N];
- int f[N];
- void solve() {
- init();
- pre();
- for (int i = 1; i <= m; i ++) {
- dp[i] = -INF;
- f[i] = -INF;
- }
- for (auto [a, b]: vec) {
- // cout << "debug: " << a << ' ' << b << endl;
- for (int i = m; i >= a; i --) {
- dp[i] = max(dp[i], dp[i - a] + b);
- }
- }
- vector<pair<int, int>> vect;
- for (int i = 1; i <= m; i ++) {
- if (dp[i] <= 0) continue;
- int k = (dp[i] * 10 - 1) / i;
- int val = v[k];
- // cout << "debug: " << dp[i] << ' ' << i << ' ' << k << ' ' << val << endl;
- for (int j = 0; (i << j) <= m; j ++) {
- vect.push_back({(i << j), (i << j) * val});
- }
- }
- // return;
- for (auto [v, w]: vect) {
- // cout << v << ' ' << w << endl;
- for (int j = m; j >= v; j --) {
- f[j] = max(f[j], f[j - v] + w);
- }
- }
- int ans = 0;
- for (int i = 1; i <= m; i ++) {
- // if (f[i] > 0) cout << i << ' ' << f[i] << endl;
- ans = max(ans, f[i]);
- }
- cout << ans << endl;
- }
- int main() {
- // pre();
- ios::sync_with_stdio(false);
- cin.tie(nullptr);
- int _ = 1;
- cin >> _;
- while (_--)
- solve();
- return 0;
- }
- /*
- 1
- 3
- 1 2
- 2 3
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement