Advertisement
Guest User

Singers' Tour

a guest
Dec 14th, 2021
330
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.31 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. const long long INFll = (long long) 1e18 + 10;
  6. const int INFii = (int) 1e9 + 10;
  7. typedef long long ll;
  8. typedef int ii;
  9. typedef long double dbl;
  10. #define endl '\n'
  11. #define sc second
  12. #define fr first
  13. #define mp make_pair
  14. #define pb push_back
  15. #define all(x) x.begin(), x.end()
  16.  
  17. #define maxn
  18.  
  19. void solve() {
  20.     ll n;
  21.     cin >> n;
  22.  
  23.     bool ok = true;
  24.     vector<ll> b;
  25.     ll sb = 0;
  26.     for(ii i = 0; i < n; i++) {
  27.         ll x; cin >> x;
  28.         b.pb(x);
  29.         sb+= x;
  30.     }
  31.  
  32.     if(sb%((n*(n+1))/2) != 0) ok = false;
  33.  
  34.     ll sa = sb/((n*(n+1))/2);
  35.  
  36.     vector<ll> a;
  37.     for(ii i = 0; i < n; i++) {
  38.         ll dif = b[(i+1)%n] - b[i];
  39.  
  40.         if((sa-dif)%n != 0 || sa-dif <= 0) ok = false;
  41.         a.pb((sa-dif)/n);
  42.     }
  43.  
  44.     for(auto x : a) {
  45.         if(x == 0) ok = false;
  46.         sa-= x;
  47.     }
  48.  
  49.     if(sa != 0 || !ok) {
  50.         cout << "NO" << endl;
  51.         return;
  52.     }
  53.  
  54.     cout << "YES" << endl;
  55.     cout << a.back() << " ";
  56.     a.pop_back();
  57.     for(auto x : a) cout << x << " ";
  58.         cout << endl;
  59.  
  60.  
  61.  
  62. }
  63.  
  64. int main() {
  65.     ios::sync_with_stdio(false); cin.tie(0);
  66.  
  67.     // freopen("in.in", "r", stdin);
  68.     //freopen("out.out", "w", stdout);
  69.  
  70.     ii tt = 1;
  71.     cin >> tt;
  72.     while(tt--) solve();
  73.  
  74. }
  75.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement