제출 #1285657

#제출 시각아이디문제언어결과실행 시간메모리
1285657Faisal_SaqibBigger segments (IZhO19_segments)C++20
0 / 100
1 ms580 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define l first #define r second const int N=1e3+100; int a[N]; ll pre[N]; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin>>n; for(int i=1;i<=n;i++)cin>>a[i],pre[i]=pre[i-1]+a[i]; ll ans=0; ll p=0; vector<pair<int,int>> rng; for(int i=1;i<=n;) { int sz=rng.size(); // cout<<"RANGES "<<i<<endl; for(int j=sz-1;j>0;j--) { while(rng[j].l<rng[j].r and (pre[rng[j].r]-pre[rng[j].l]) >= (pre[rng[j].l]-pre[rng[j-1].l-1])) { rng[j].l++; rng[j-1].r++; } } // for(int j=0;j<sz;j++) // { // cout<<rng[j].l<<' '<<rng[j].r<<endl; // } if(rng.size()>0) p=pre[rng.back().r]-pre[rng.back().l-1]; ll sm=a[i]; int j=i+1; while(sm<p and j<=n) { sm+=a[j]; j++; } rng.push_back({i,j-1});// inc inc if(sm<p) { break; } else { ans++; p=sm; i=j; } } cout<<ans<<endl; }
#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...