Advertisement
Saleh127

CF 1427A

Oct 10th, 2020
59
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define test int t; cin>>t; for(int cs=1;cs<=t;cs++)
  5. int main()
  6. {
  7. ios_base::sync_with_stdio(0);
  8. cin.tie(0);
  9. cout.tie(0);
  10. ///~!B}]
  11.  
  12. test
  13. {
  14. ll a[10000],c,d,e=0,f,i,j,k,l;
  15. cin>>c;
  16. for(i=0; i<c; i++)
  17. {
  18. cin>>a[i];
  19. }
  20. sort(a,a+c,greater<int>());
  21. for(i=0; i<c; i++)
  22. {
  23. e+=a[i];
  24. if(e==0)
  25. {
  26. break;
  27. }
  28. }
  29. if(e==0)
  30. {
  31. sort(a,a+c);
  32. e=0;
  33. for(i=0; i<c; i++)
  34. {
  35. e+=a[i];
  36. if(e==0)
  37. {
  38. break;
  39. }
  40. }
  41. if(e==0)
  42. {
  43. cout<<"NO"<<endl;
  44. continue;
  45. }
  46. else
  47. {
  48. cout<<"YES"<<endl;
  49. for(i=0; i<c; i++)
  50. {
  51. cout<<a[i]<<" ";
  52. }
  53. cout<<endl;
  54. }
  55.  
  56. }
  57. else
  58. {
  59. cout<<"YES"<<endl;
  60. for(i=0; i<c; i++)
  61. {
  62. cout<<a[i]<<" ";
  63. }
  64. cout<<endl;
  65. }
  66.  
  67.  
  68. }
  69.  
  70.  
  71. return 0;
  72. }
  73.  
Advertisement
RAW Paste Data Copied
Advertisement