Submission #441543

#TimeUsernameProblemLanguageResultExecution timeMemory
441543leakedBigger segments (IZhO19_segments)C++14
0 / 100
1 ms312 KiB
#include <bits/stdc++.h> #define vec vector using namespace std; typedef long long ll; signed main(){ ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); int n; cin>>n; vec<int>a(n); vec<ll>pref(n); for(auto &z : a) cin>>z; for(int i=0;i<n;i++){ pref[i]=(i?pref[i-1]:0)+a[i]; } auto get=[&](int l,int r){ return pref[r]-pref[l-1]; }; ll lst=a[0],s=0; int cnt=1; int w=0; for(int i=1;i<n;i++){ s+=a[i]; if(s>=lst){ int j=w; while(1){ if(pref[i]-pref[j]<pref[j]-pref[w]+lst) break; j++; } j--; cnt++; lst=pref[i]-pref[j]; w=i; s=0; } } cout<<cnt; return 0; }

Compilation message (stderr)

segments.cpp: In function 'int main()':
segments.cpp:18:10: warning: variable 'get' set but not used [-Wunused-but-set-variable]
   18 |     auto get=[&](int l,int r){
      |          ^~~
#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...