掉大分补提 D
点击查看代码
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int,int> PLL;
#define IOS cin.tie(nullptr)->sync_with_stdio(false);
#define se second
#define fi first
#define mem(a,b) memset(a,b,sizeof a);
#define pri priority_queue<int,vector<int>,greater<int> >
#define low(a,b,c) lower_bound(a,a+b,c)-a;
#define upp(a,b,c) upper_bound(a,a+b,c)-a;
const int N=1e7+7;
LL a[N];
LL b[N];
void solve()
{
int n;
cin>>n;
for(int i=1;i<=n;i++) cin>>a[i];
sort(a+1,a+1+n);
LL w=a[n]-a[1];
int pos=lower_bound(a+1,a+1+n,0)-a;
if(a[1]==0||n==1)
{
cout<<"No\n";
return ;
}
b[1]=a[1];
int ii=2,j=pos;
LL a0=a[1];
int flag=1;
int k=1;
for(int i=2;i<=n;i++)
{
if(a0<0&&j<=n)
{
b[i]=a[j];
a0+=a[j++];
}
else
{
a0+=a[ii];
b[i]=a[ii++];
}
}
if(flag)
{
cout<<"Yes\n";
for(int i=1;i<n;i++)
{
cout<<b[i]<<" ";
}
cout<<b[n]<<"\n";
}
else cout<<"No\n";
}
int main()
{
int t=1;
cin>>t;
while(t--)
{
solve();
}
return 0;
}