fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define el "\n"
  4. #define ll long long
  5. #define ull unsigned long long
  6. #define se second
  7. #define fi first
  8. #define be begin()
  9. #define en end()
  10. #define Faster cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
  11. bool isExBalance(int *a, int n)
  12. {
  13. ll f[n] = {0};
  14. f[0] = a[0];
  15. if(n <= 2) return false;
  16. for(int i = 1; i < n; i++)
  17. {
  18. f[i] = f[i-1] + a[i];
  19. }
  20. for(int i = 1; i < n - 1; i++)
  21. {
  22. if((f[n - 1] - f[i]) != 0 && f[i - 1] % (f[n - 1] - f[i]) == 0) return true;
  23. }
  24. return false;
  25. }
  26. int main()
  27. {
  28. Faster;
  29. int n; cin >> n;
  30. int *a = new int[n];
  31. for(int i = 0; i < n; i++) cin >> a[i];
  32. if(isExBalance(a, n)) cout << "YES";
  33. else cout << "NO";
  34.  
  35. }
  36.  
Success #stdin #stdout 0.01s 5288KB
stdin
5
6 0 0 1 2
stdout
YES