이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define fs first
#define ss second
#define str string
#define all(a) a.begin(), a.end()
#define print(a) \
for (auto x : a) \
cout << x << ' '; \
cout << endl;
#define each(x, a) for (auto x : a)
struct node {
int s, l, r;
};
void solve()
{
int n;
cin >> n;
vector<int> a(n);
for(int i = 0; i < n; i ++)
cin >> a[i];
vector<node> p;
p.push_back({a[0], 0, 0});
int l = 1, r = 1, s = 0, ans = 1;
while(r < n and l < n){
while(r < n and p.back().s > s)
s += a[r], r ++;
if(p.back().s <= s)
ans ++;
p.push_back({s, l, r});
for(int i = p.size() - 1; i >= 1; i --){
while(p[i].s - a[p[i].l] >= p[i - 1].s + a[p[i].l])
p[i].s -= a[p[i].l], p[i - 1].s += a[p[i].l], p[i].l ++, p[i - 1].r ++;
}
l = r;
s = 0;
}
cout << ans << endl;
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int t = 1;
// cin >> t;
while (t--)
{
solve();
cout << endl;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |