#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
using namespace std;
//typedef tree<int,null_type,less_equal<int>,rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define mem(a,x) memset(a,x,sizeof(a))
#define int long long
#define fast(s) s.reserve(2000); s.max_load_factor(0.5);
#define F first
#define S second
#define pii pair<int,int>
#define iii tuple<int,int,int>
#define all(p) p.begin(), p.end()
template<typename T> bool maximum(T &A, const T &B) {return A<B? A=B, true: false;}
template<typename T> bool minimum(T &A, const T &B) {return A>B? A=B, true: false;}
template<typename T> T gcd(T t) {return t;}
template<typename T, typename... Args> T gcd(T t, Args... args) {return __gcd(t,args...);};
void print(bool condition=1) {cout<<(condition? "YES\n": "NO\n");}
const int mod=1e9+7;
const int INF=1e18;
const int N=5e5+5;
int n, a[N];
pii dp[N];
void file()
{
#define task "main"
if(fopen(task".inp","r"))
{
freopen(task".inp","r",stdin);
freopen(task".out","w",stdout);
}
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
}
void Solve()
{
cin>>n;
for(int i=1; i<=n; ++i) cin>>a[i];
for(int i=1; i<=n; ++i) a[i]+=a[i-1];
dp[0]={1,0};
for(int i=1; i<=n; ++i)
{
maximum(dp[i],dp[i-1]);
int j=lower_bound(a+i,a+n+1,2*a[i]-dp[i].S)-a;
maximum(dp[j],make_pair(dp[i].F+1,a[i]));
}
cout<<dp[n].F;
}
signed main()
{
file();
Solve();
cerr<<"Time: "<<1.0*clock()/CLOCKS_PER_SEC;
return 0;
}
Compilation message (stderr)
segments.cpp: In function 'void file()':
segments.cpp:30:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
30 | freopen(task".inp","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
segments.cpp:31:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
31 | freopen(task".out","w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# | 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... |