day3
作者:
__492
,
2024-05-30 20:32:07
,
所有人可见
,
阅读 1
#include <bits/stdc++.h>
using namespace std;
const int N = 2e6+9;
int n;
int a[N],s[N];
int main()
{
cin >> n;
for (int i = 1; i <= n; i++)cin >> a[i];
for (int i = 1; i <= n - 1; i++)a[i + n] = a[i];
for (int i = 1; i <= 2 * n - 1; i++)s[i] = s[i - 1] + a[i];
deque<int>q;
int ans = 0;
for (int i = 1; i <= 2 * n - 1; i++)
{
while (q.size() && max(i - n + 1, 1) > q.front())
q.pop_front();
while (q.size() && s[i] <= s[q.back()])
q.pop_back();
q.push_back(i);
if (i - n + 1 > 0 && s[q.front()] - s[i - n] >= 0)ans++;
}
cout << ans;
return 0;
}