Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- const long long INFll = (long long) 1e18 + 10;
- const int INFii = (int) 1e9 + 10;
- typedef long long ll;
- typedef int ii;
- typedef long double dbl;
- #define endl '\n'
- #define sc second
- #define fr first
- #define mp make_pair
- #define pb push_back
- #define all(x) x.begin(), x.end()
- #define maxn
- void solve() {
- ll n;
- cin >> n;
- bool ok = true;
- vector<ll> b;
- ll sb = 0;
- for(ii i = 0; i < n; i++) {
- ll x; cin >> x;
- b.pb(x);
- sb+= x;
- }
- if(sb%((n*(n+1))/2) != 0) ok = false;
- ll sa = sb/((n*(n+1))/2);
- vector<ll> a;
- for(ii i = 0; i < n; i++) {
- ll dif = b[(i+1)%n] - b[i];
- if((sa-dif)%n != 0 || sa-dif <= 0) ok = false;
- a.pb((sa-dif)/n);
- }
- for(auto x : a) {
- if(x == 0) ok = false;
- sa-= x;
- }
- if(sa != 0 || !ok) {
- cout << "NO" << endl;
- return;
- }
- cout << "YES" << endl;
- cout << a.back() << " ";
- a.pop_back();
- for(auto x : a) cout << x << " ";
- cout << endl;
- }
- int main() {
- ios::sync_with_stdio(false); cin.tie(0);
- // freopen("in.in", "r", stdin);
- //freopen("out.out", "w", stdout);
- ii tt = 1;
- cin >> tt;
- while(tt--) solve();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement