Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include <bits/stdc++.h>
- using namespace std;
- #define int long long
- #define double long double
- int n, m, q;
- vector<int> a, pref;
- vector<pair<int, int> > b;
- bool comp(pair<int, int> i, pair<int, int> j) {
- if (i.second * j.first == j.second * i.first) return i.first > j.first;
- else return i.second * j.first < j.second * i.first;
- }
- signed main() {
- ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
- cout << fixed << setprecision(20);
- #ifdef _DEBUG
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- #endif
- cin >> n;
- a.resize(n);
- pref.resize(n + 1, 0);
- for (auto& i : a) cin >> i;
- sort(a.rbegin(), a.rend());
- for (int i = 0; i < n; ++i) {
- pref[i + 1] = pref[i] + a[i];
- }
- cin >> m;
- b.resize(m);
- for (auto& i : b) cin >> i.first >> i.second;
- sort(b.begin(), b.end(), comp);
- cin >> q;
- while (q--) {
- int d;
- cin >> d;
- int ans = 0;
- for (int k = 0; k <= min(d, n); ++k) {
- int x = 1e4 + pref[k], cnt = 0;
- for (int i = 0; i < min(d - k, m); ++i) {
- cnt += x * b[i].first, x -= b[i].second;
- }
- ans = max(ans, cnt);
- }
- cout << ans << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement