Advertisement
Mahedi22

Untitled

May 4th, 2021
738
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.49 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. #include <ext/pb_ds/assoc_container.hpp>
  3. #include <ext/pb_ds/tree_policy.hpp>
  4. #include <ext/pb_ds/detail/standard_policies.hpp>
  5. using namespace __gnu_pbds;
  6. using namespace std;
  7.  
  8. #define rep(i,a,b)     for(int i = a; i<b; i++)
  9. #define ll             long long
  10. #define pb             push_back
  11. #define p              pop_back
  12. #define pf             push_front
  13. #define ppf            pop_front
  14. #define all(a)         a.begin(),a.end()
  15. #define rall(a)        a.rbegin(),a.rend()
  16. #define sz(a)          (int)a.size()
  17. #define F              first
  18. #define S              second
  19. #define endl           '\n'
  20. typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
  21.  
  22.  
  23. int main()
  24. {
  25.     ios::sync_with_stdio(0),cin.tie(0);
  26.     #ifndef ONLINE_JUDGE
  27.     freopen("input.txt","r",stdin);
  28.     freopen("output.txt","w",stdout);
  29.     #endif
  30.  
  31.    
  32.     int t;
  33.     cin>>t;
  34.     while(t--){
  35.         int n, x;
  36.         cin>>n>>x;
  37.         vector<int>v(n);
  38.         int s = 0;
  39.         for(int i = 0; i<n; i++) cin>>v[i], s+= v[i];
  40.         if(s==x){
  41.             cout<<"NO"<<endl;
  42.             continue;
  43.         }
  44.        
  45.         s = 0;
  46.         for(int i=0; i<n-1; i++){
  47.             s +=v[i];
  48.             if(s==x){
  49.                 swap(v[i],v[i+1]);
  50.                 break;
  51.             }
  52.         }
  53.         cout<<"YES"<<endl;
  54.         for(int i=0;i<n;i++)cout<<v[i]<<' ';
  55.         cout<<endl;
  56.  
  57.     }    
  58.    
  59.    
  60.    
  61.  
  62.     return 0;
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement