fork download
  1. #include <bits/stdc++.h>
  2. #include <ext/pb_ds/assoc_container.hpp>
  3. #include <ext/pb_ds/tree_policy.hpp>
  4. using namespace __gnu_pbds;
  5. using namespace std;
  6. #define pbds tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; // - Use 'less<T>' for set, 'less_equal<T>' for multiset
  7. #define ll long long int
  8. #define ull unsigned long long
  9. #define endl "\n"
  10.  
  11. int main()
  12. {
  13.  
  14. ios::sync_with_stdio(false);
  15. cin.tie(nullptr);
  16.  
  17. int n;
  18. cin >> n;
  19.  
  20. deque<int> v;
  21. for (int i = 0; i < n; i++)
  22. {
  23. int val;
  24. cin >> val;
  25. v.push_back(val);
  26. }
  27.  
  28. ll ans = 0 ;
  29.  
  30. for (int i = 0; i < n; i++)
  31. {
  32. int cnt = 0;
  33. if (i == 0)
  34. {
  35.  
  36. ll val = v[0];
  37. if (val < 0)
  38. {
  39. cnt++;
  40. }
  41.  
  42. for (int j = 1; j < n; j++)
  43. {
  44.  
  45. val += v[j];
  46.  
  47. if (val < 0)
  48. {
  49. cnt++;
  50. }
  51. }
  52. }
  53. else
  54. {
  55. v.push_back(v[0]);
  56. v.pop_front();
  57.  
  58. ll val = v[0];
  59. if (val < 0)
  60. {
  61. cnt++;
  62. }
  63.  
  64. for (int j = 1; j < n; j++)
  65. {
  66.  
  67. val += v[j];
  68.  
  69. if (val < 0)
  70. {
  71. cnt++;
  72. }
  73. }
  74. }
  75.  
  76. if(cnt == 0){
  77. ans++;
  78.  
  79. }
  80. }
  81. cout << ans ;
  82.  
  83. return 0;
  84. }
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
Standard output is empty