C题
先把所有蛋糕重量加起来,然后用总重量开始切,如果切出来的有现存的,则可以同时去掉;
如果没有,则继续切;如果最大的重量比现存的都小的话,结果肯定是切不出来
#include<bits/stdc++.h>
using namespace std;
void solve()
{
int n;
cin>>n;
priority_queue<long long,vector<long long>,less<long long>>has,now;
long long sum=0;
for(int i=1;i<=n;i++){
int temp;
cin>>temp;
sum+=temp;
has.push(temp);
}
now.push(sum);
while(1)
{
if(now.top()<has.top())
{
cout<<"NO\n";
return;
}
while(now.top()==has.top()){
now.pop();has.pop();
if(!now.size())break;
}
if(!now.size())break;
long long a=now.top();
now.pop();
now.push(a/2);now.push((a+1)/2);
if(a/2==0)break;
}
if(now.size())cout<<"NO\n";
else cout<<"YES\n";
}
int main()
{
int t;
cin>>t;
while(t--)
{
solve();
}
}