제출 #863125

#제출 시각아이디문제언어결과실행 시간메모리
863125Nikhil2946Bigger segments (IZhO19_segments)C++14
13 / 100
1 ms500 KiB
#include<bits/stdc++.h> using namespace std; #define ll long long int #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define deb(x) cout << #x << "=" << x << endl #define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl const ll N=5005; const ll mod=1e9+7; void upd(pair<int, int> &a, pair<int, int> b) { if (a.first < b.first) a = b; if (a.first == b.first) a = min(a, b); } void solve() { int n; cin>>n; vector<int>a(n),prf(n+1); for(int i=0;i<n;i++) { cin>>a[i]; prf[i+1]=a[i]+prf[i]; } vector<pair<int,int>>dp(n+1,{-1e9,0}); dp[0]={0,0}; for(int i=0;i<n;i++) { for(int j=i+1;j<=n;j++) { int vl = prf[j] - prf[i]; if(dp[i].second<=vl) { pair<ll,ll> opt1=dp[j]; pair<ll,ll> opt2={dp[i].first+1,vl}; dp[j].first=max(opt1.first,opt2.first); // if opt1.first==opt2.first then min value segment is preferable if(dp[j].first==opt2.first) { dp[j].second=opt2.second; } else { dp[j].second=opt1.second; } } } } cout<<dp[n].first<<endl; } int main() { IOS; ll T; T=1; // cin >> T; while(T--){ solve(); } return 0; }
#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...