thecodecird

Umesh and Marbles

Sep 27th, 2021
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.45 KB | None | 0 0
  1. #include "bits/stdc++.h"
  2.  
  3. #define faster ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
  4.  
  5. #define ll long long int
  6.  
  7. #define pb push_back
  8.  
  9. #define f(a) for(ll i = 0;i<a;i++)
  10.  
  11. #define ffor(i,a,b) for(ll i = a;i<b;i++)
  12.  
  13. #define rfor(i,a,b) for(ll i = a;i>b;i--)
  14.  
  15. #define sll set<ll>
  16.  
  17. #define mll map<ll,ll>
  18.  
  19. #define vll vector<ll>
  20.  
  21. #define pll pair<ll,ll>
  22.  
  23. #define mcl map<char,ll>
  24.  
  25. #define usll unordered_set<ll,ll>
  26.  
  27. #define umll unordered_map<ll,ll>
  28.  
  29. #define umcl unordered_map<char,ll>
  30.  
  31. #define pqg priority_queue<ll>
  32.  
  33. #define pqs priority_queue<ll,vll,greater<ll> >
  34.  
  35. #define T ll t; cin>>t; while(t--)
  36.  
  37. #define freeopen freopen("input.txt","r",stdin);
  38.  
  39. #define freeclose freopen("output.txt","w",stdout);
  40.  
  41. #define MOD 1000000007
  42.  
  43. #define setbits(x) __builtin_popcountll(x)
  44.  
  45. #define INF 1000000000000000000
  46.  
  47. #define all(x) x.begin(), x.end()
  48.  
  49. using namespace std;
  50.  
  51. ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
  52.  
  53. ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }
  54.  
  55. ll modpower(ll x,ll y,ll m){if(y==0)return 1;ll p=modpower(x,y/2,m)%m;p=(p*p)%m;return (y%2==0)?p:(x*p)%m;}
  56.  
  57.  
  58. ll power(ll a,ll b)
  59.  
  60. {
  61.  
  62.     ll ans = 1;
  63.  
  64.     while(b) {
  65.  
  66.         if(b&1) ans = ans * a;
  67.  
  68.         a = a * a;
  69.  
  70.         b >>= 1;
  71.  
  72.     }
  73.  
  74.     return ans;
  75.  
  76. }
  77.  
  78. bool isPrime(ll n)
  79.  
  80. {
  81.     if (n <= 1)
  82.  
  83.         return false;
  84.  
  85.     if (n <= 3)
  86.  
  87.         return true;
  88.  
  89.  
  90.  
  91.     if (n % 2 == 0 || n % 3 == 0)
  92.  
  93.         return false;
  94.  
  95.     for (ll i = 5; i * i <= n; i = i + 6)
  96.  
  97.         if (n % i == 0 || n % (i + 2) == 0)
  98.  
  99.             return false;
  100.  
  101.     return true;
  102.  
  103. }
  104.  
  105. main()
  106.  
  107. {
  108.  
  109.     faster
  110.  
  111.     T
  112.  
  113.     {
  114.  
  115.         ll n;
  116.  
  117.         cin>>n;
  118.  
  119.  
  120.  
  121.         ll a[n];
  122.  
  123.         ll sum=0;
  124.  
  125.         f(n){
  126.  
  127.             cin>>a[i];
  128.  
  129.             sum+=a[i];
  130.  
  131.         }
  132.         if(sum%(n-1))
  133.  
  134.             cout<<"NO\n";
  135.  
  136.         else
  137.  
  138.         {
  139.  
  140.             ll actualsum=sum/(n-1);
  141.  
  142.             bool cheaker=true;
  143.  
  144.             f(n)
  145.  
  146.             {
  147.  
  148.                 if(actualsum-a[i]>=0)
  149.  
  150.                     a[i]=actualsum-a[i];
  151.  
  152.                 else
  153.  
  154.                 {
  155.  
  156.                     cheaker=false;
  157.  
  158.                 }
  159.             }
  160.  
  161.             if(cheaker)
  162.  
  163.             {
  164.                 cout<<"YES\n";
  165.  
  166.                 f(n)
  167.  
  168.                 cout<<a[i]<<" ";
  169.  
  170.                 cout<<"\n";
  171.  
  172.             }
  173.             else
  174.                 cout<<"NO\n";
  175.  
  176.         }
  177.  
  178.     }
  179.  
  180. }
Advertisement
Add Comment
Please, Sign In to add comment