B

 avatar
user_8384735
c_cpp
3 years ago
937 B
5
Indexable
// 1224B.cpp
#include<iostream>
#include<set>
#include<vector>
#include<cstring>
#include<algorithm>
#include<queue>
using namespace std;
using ll = unsigned long long;
int n, m;
struct node{
	ll poi;
	bool x;
	node (ll u = 0, bool v = 0) : poi(u) , x(v){}
	bool operator < (const node y) const {
		if (!this->x) return 0;
		else if (!y.x) return 1;
		else return y.poi > this->poi; 
	}
};

priority_queue<node> q;
vector<ll> x;
vector<ll> y;
int main(){
	cin >> n >> m;
	x.resize(n); for (ll &z : x) cin >> z;
	y.resize(m); for (ll &w : y) cin >> w;
	sort(y.begin(), y.end());
	int k = 0, i = 1;
	for (ll z : x){
		if (i++ == y[k]) q.push(node(z, 1)), k++;
		else q.push(node(z, 0));
	}
	ll res = 0;
	while (q.size()){
		node w = q.top();
		// cout << w.x << w.poi << " " << endl;
		if (w.x && res > w.poi){
			res <<= 1ll;
		}else res += w.poi *1ll;
		q.pop();
	}
	cout << res;
	return 0;
}
Editor is loading...