Submission #545421

#TimeUsernameProblemLanguageResultExecution timeMemory
545421krit3379Bigger segments (IZhO19_segments)C++17
100 / 100
88 ms12048 KiB
#include<bits/stdc++.h> using namespace std; #define N 500005 long long a[N]; pair<int,long long> dp[N]; int main(){ int n,i; scanf("%d",&n); for(i=1;i<=n;i++)scanf("%lld",&a[i]),a[i]+=a[i-1]; dp[0]={1,0}; for(i=1;i<=n;i++){ dp[i]=max(dp[i],dp[i-1]); int pos=lower_bound(a+1,a+n+1,2*a[i]-dp[i].second)-a; dp[pos]=max(dp[pos],{dp[i].first+1,a[i]}); } printf("%d",dp[n].first); return 0; }

Compilation message (stderr)

segments.cpp: In function 'int main()':
segments.cpp:10:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   10 |     scanf("%d",&n);
      |     ~~~~~^~~~~~~~~
segments.cpp:11:27: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 |     for(i=1;i<=n;i++)scanf("%lld",&a[i]),a[i]+=a[i-1];
      |                      ~~~~~^~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...