Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- long long sums[100001];
- int main()
- {
- int n, p;
- cin >> n >> p;
- vector<int> v;
- multiset<long long> ms;
- long long sum = 0;
- for(int i = 0; i < n; i++) {
- int x;
- cin >> x;
- v.push_back(x);
- ms.insert(x);
- sum += x;
- }
- sums[0] = sum;
- for(int i = 0; i < n - 1; i++) {
- long long najmal = *ms.begin();
- long long najgolem = *ms.rbegin();
- ms.erase(ms.find(najmal));
- ms.erase(ms.find(najgolem));
- ms.insert(najgolem - najmal);
- sum -= (najgolem + najmal);
- sum += najgolem - najmal;
- sums[i + 1] = sum;
- }
- for(int i = 0; i < p; i++) {
- int x;
- cin >> x;
- cout << sums[x] << endl;
- }
- return 0;
- }
- // 2 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement