用STL优先队列进行模拟
但是求小根堆
好像是
priority_queue <ll, vector<ll>, greater<> > PQ;
比较麻烦
直接默认PQ塞负数也可以解决
//#pragma GCC optimize(2)
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <string>
#include <cstring>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <ctime>
#include <vector>
#include <fstream>
#include <list>
#include <iomanip>
#include <numeric>
using namespace std;
typedef long long ll;
const int MAXN = 1e6 + 10;
ll ans;
priority_queue <ll> PQ;
int main()
{
//ios::sync_with_stdio(false);
//cin.tie(0); cout.tie(0);
ll n, m, tmp, ta, tb;
cin>>n>>m;
for(int i = 0; i < n; i++)
{
cin>>tmp;
PQ.push(-tmp);
}
while(PQ.size() != 1)
{
ta = PQ.top();
PQ.pop();
tb = PQ.top();
PQ.pop();
if(ta == tb)
{
PQ.push(2 * ta);
}
else
{
PQ.push(2 * max(ta, tb));
}
}
ans = -PQ.top();
cout<<ans<<endl;
return 0;
}