by @[Larryyu](https://www.luogu.com.cn/user/475329)
## 题目描述
The only difference between the two versions is that in this version, the constraints are higher.
Initially, array contains just the number . You can perform several operations in order to change the array. In an operation, you can select some subsequence of and add into an element equal to the sum of all elements of the subsequence.
You are given a final array . Check if can be obtained from the initial array by performing some number (possibly 0) of operations on the initial array.
A sequence is a subsequence of a sequence if can be obtained from by the deletion of several (possibly zero, but not all) elements. In other words, select ( ) distinct indices and insert anywhere into a new element with the value equal to .
## 输入格式
The first line of the input contains an integer ( ) — the number of test cases. The description of the test cases follows.
The first line of each test case contains a single integer ( ) — the number of elements the final array should have.
The second line of each test case contains space-separated integers ( ) — the elements of the final array that should be obtained from the initial array .
It is guaranteed that the sum of over all test cases does not exceed .
## 输出格式
For each test case, output "YES" (without quotes) if such a sequence of operations exists, and "NO" (without quotes) otherwise.
You can output the answer in any case (for example, the strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive answer).
For the first test case, the initial array is already equal to , so the answer is "YES".
For the second test case, performing any amount of operations will change to an array of size at least two which doesn't only have the element , thus obtaining the array is impossible and the answer is "NO".
For the third test case, we can perform the following operations in order to obtain the final given array :
- Initially, . - By choosing the subsequence , and inserting in the array, changes to . - By choosing the subsequence , and inserting in the middle of the array, changes to . - By choosing the subsequence , and inserting after the first of the array, changes to . - By choosing the subsequence and inserting at the beginning of the array, changes to (which is the array we needed to obtain).
//Subsequence Addition
//只需要新添加的数小于前几个数的前缀和就可以了#include <bits/stdc++.h>
#define int long long
usingnamespace std;
constint N=1e6+10,mod=1e9+7;
int s[N];
int n,t,a[N],f[N],res,num,ans,m;
bool vis[N];
signed main()
{
std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
cin>>t;
while(t--){
cin>>n;
bool f=false;
for(int i=1;i<=n;i++) cin>>a[i];
sort(a+1,a+n+1);
for(int i=1;i<=n;i++) s[i]=s[i-1]+a[i];
if(s[1]!=1) f=true;
for(int i=2;i<=n;i++) if(a[i]>s[i-1]) f=true;
if(f) cout<<"NO"<<endl;
else cout<<"YES"<<endl;
}
return0;
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· winform 绘制太阳,地球,月球 运作规律
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)