Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- //иброгим
- #define loop(i,n) for(int i = 0; i<n; ++i)
- #define all(a) a.begin(),a.end()
- #define FOR(i,n,m) for(int i = n; i<m; ++i)
- #define rall(a) a.rbegin(),a.rend()
- #define fr first
- #define sc second
- #define mp(a,b) make_pair(a,b)
- #define int long long
- using namespace std;
- int s1,d1,l1,r1;
- int s2,d2,l2,r2;
- bool comp(pair <int,int> i, pair <int,int> j)
- {
- if (i.second * j.first == j.second * i.first) return i.first > j.first;
- return (i.second * j.first < j.second * i.first);
- }
- signed main() {
- ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
- int n;
- cin >> n;
- vector <int> norm(n);
- loop(i,n) cin >> norm[i];
- int m;
- cin >> m;
- vector <pair <int,int> > pod(m);
- loop(i,m) cin >> pod[i].first >> pod[i].second;
- sort(all(pod), comp);
- sort(rall(norm));
- int q;
- cin >> q;
- vector <int> pref(n+1,0);
- loop(i,n) pref[i+1] = pref[i] + norm[i];
- vector <int> kekis(m);
- loop(i,m) kekis[i] = i;
- while(q--)
- {
- int ans = 0;
- int a, sum;
- cin >> a;
- if (m < 6)
- {
- loop(i, n+1)
- {
- int nval = a - i;
- sort(all(kekis));
- do
- {
- sum = 0;
- int chubzik = 1e4 + pref[i];
- loop(j, min(m, nval))
- {
- sum += pod[kekis[j]].first * chubzik;
- chubzik -= pod[kekis[j]].second;
- }
- ans = max(sum, ans);
- } while (next_permutation(all(kekis)));
- }
- cout << ans << endl;
- } else
- {
- loop(i,n + 1)
- {
- sum = 0;
- int chubzik = 1e4 + pref[i], nval = a - i;
- loop(j, min(m,nval))
- {
- sum += pod[j].first * chubzik;
- chubzik -= pod[j].second;
- }
- ans = max(ans, sum);
- }
- cout << ans << endl;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement