Advertisement
Guest User

Untitled

a guest
Dec 14th, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.32 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4.  
  5. #define int long long
  6. #define double long double
  7.  
  8. int n, m, q;
  9. vector<int> a, pref;
  10. vector<pair<int, int> > b;
  11.  
  12. bool comp(pair<int, int> i, pair<int, int> j) {
  13.     if (i.second * j.first == j.second * i.first) return i.first > j.first;
  14.     else return i.second * j.first < j.second * i.first;
  15. }
  16.  
  17. signed main() {
  18.     ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
  19.     cout << fixed << setprecision(20);
  20. #ifdef _DEBUG
  21.     freopen("input.txt", "r", stdin);
  22.     freopen("output.txt", "w", stdout);
  23. #endif
  24.     cin >> n;
  25.     a.resize(n);
  26.     pref.resize(n + 1, 0);
  27.     for (auto& i : a) cin >> i;
  28.     sort(a.rbegin(), a.rend());
  29.     for (int i = 0; i < n; ++i) {
  30.         pref[i + 1] = pref[i] + a[i];
  31.     }
  32.     cin >> m;
  33.     b.resize(m);
  34.     for (auto& i : b) cin >> i.first >> i.second;
  35.     sort(b.begin(), b.end(), comp);
  36.  
  37.     cin >> q;
  38.     while (q--) {
  39.         int d;
  40.         cin >> d;
  41.         int ans = 0;
  42.         for (int k = 0; k <= min(d, n); ++k) {
  43.             int x = 1e4 + pref[k], cnt = 0;
  44.             for (int i = 0; i < min(d - k, m); ++i) {
  45.                 cnt += x * b[i].first, x -= b[i].second;
  46.             }
  47.             ans = max(ans, cnt);
  48.         }
  49.         cout << ans << endl;
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement