-
Notifications
You must be signed in to change notification settings - Fork 6
/
AvoidingZeroes
97 lines (79 loc) · 1.78 KB
/
AvoidingZeroes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#include <bits/stdc++.h>
#define MOD 1000000007
#define test int t; cin>>t; while(t--)
#define init(arr,val) memset(arr,val,sizeof(arr))
#define loop(i,a,b) for(int i=a;i<b;i++)
#define loopr(i,a,b) for(int i=a;i>=b;i--)
#define loops(i,a,b,step) for(int i=a;i<b;i+=step)
#define looprs(i,a,b,step) for(int i=a;i>=b;i-=step)
#define ull unsigned long long int
#define ll long long int
#define P pair
#define PLL pair<long long, long long>
#define PII pair<int, int>
#define PUU pair<unsigned long long int, unsigned long long int>
#define L list
#define V vector
#define D deque
#define ST set
#define MS multiset
#define M map
#define UM unordered_map
#define mp make_pair
#define pb push_back
#define pf push_front
#define MM multimap
#define F first
#define S second
#define IT iterator
#define RIT reverse_iterator
#define FAST ios_base::sync_with_stdio(false);cin.tie();cout.tie();
#define FILE_READ_IN freopen("input.txt","r",stdin);
#define FILE_READ_OUT freopen("output.txt","w",stdout);
#define all(a) a.begin(),a.end()
using namespace std;
// For ordered_set
const ll maxn = 1e5;
const ll inf = 1e9;
const double pi = acos(-1);
void solve(){
ll n;
cin>>n;
vector<ll>v(n);
vector<ll>g;
vector<ll>l;
vector<ll>e;
ll sum=0;
for(ll i =0;i<n;i++){
cin>>v[i];
sum+=v[i];
if(v[i]>0)g.pb(v[i]);
else if (v[i]==0)e.pb(v[i]);
else l.pb(v[i]);
}
if(sum!=0){
cout<<"YES"<<endl;
if(sum>0){
for(auto el:g) cout<<el<<" ";
for(auto el:e) cout<<el<<" ";
for(auto el:l) cout<<el<<" ";
}
else{
for(auto el:l) cout<<el<<" ";
for(auto el:e) cout<<el<<" ";
for(auto el:g) cout<<el<<" ";
}
cout<<endl;
}
else{
cout<<"NO"<<endl;
}
}
int main(){
int t = 0;
cin >> t;
while(t--){
solve();
}
return 0;
}