#include "bits/stdc++.h"
using namespace std;
#define ff first
#define ss second
#define all(v) v.begin(), v.end()
#define ll long long
#define pb push_back
#define pii pair<int, int>
#define pli pair<ll, int>
#define pll pair<ll, ll>
#define tr(i, c) for(auto i = c.begin(); i != c.end(); ++i)
#define wr puts("----------------")
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<=b){a=b;return 1;}return 0;}
const int N = 5e5+5;
int v[N], ans[N];
ll par[N];
struct node {
int in, val;
ll sm;
node(){
sm=0, in=0, val=0;
};
} dp[N];
int main(){
int n;
scanf("%d", &n);
for(int i = 1; i <= n; ++i)
scanf("%d", v+i), par[i]=par[i-1]+v[i];
vector<ll> A;
for(int i = 0; i <= n; ++i)
A.pb(par[i]);
// tr(it, A)
// printf("%lld ", *it);
// puts("");wr;
for(int i = 1; i <= n; ++i)
dp[i].sm=par[i], dp[i].in=0, dp[i].val=1;
for(int i = 1; i <= n; ++i){
int l=lower_bound(all(A), 2*par[i]-par[dp[i].in])-A.begin();
if(umax(dp[l].val, dp[i].val+1))
dp[l].sm=par[l]-par[i], dp[l].in=i;
}
int answer=0;
for(int i = 1; i <= n; ++i)
umax(answer, dp[i].val);
printf("%d\n", answer);
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
segments.cpp: In function 'int main()':
segments.cpp:29:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
29 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
segments.cpp:31:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
31 | scanf("%d", v+i), par[i]=par[i-1]+v[i];
| ~~~~~^~~~~~~~~~~
# | 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... |