fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define Samurai ios_base::sync_with_stdio(false), cout.tie(NULL), cin.tie(NULL);
  4.  
  5. int main(){ Samurai
  6. int _t = 1;
  7. cin >> _t;
  8. for (int i = 1; i <= _t; i++){
  9. int n; cin >> n;
  10. int arr[n];
  11. long long avg = 0;
  12. for(int i=0; i<n; i++){
  13. cin >> arr[i];
  14. avg += arr[i];
  15. }
  16. if(avg%n != 0){
  17. cout << "NO\n";
  18. }
  19. else{
  20. avg/=n;
  21. for(int i=1; i<n-1; i++){
  22. if(arr[i-1] < avg){
  23. arr[i+1] -= (avg - arr[i-1]);
  24. arr[i-1] = avg;
  25. }
  26. else if(arr[i-1] > avg){
  27. arr[i+1] += (arr[i-1] - avg);
  28. arr[i-1] = avg;
  29. }
  30. }
  31. bool ok = true;
  32. for(int i=0; i<n-1; i++){
  33. if(arr[i] != arr[i+1]){
  34. ok = false;
  35. cout << "NO\n";
  36. break;
  37. }
  38. }
  39. if(ok) cout << "YES\n";
  40. }
  41. }
  42. return 0;
  43. }
  44.  
  45.  
Success #stdin #stdout 0.01s 5268KB
stdin
Standard input is empty
stdout
NO