Submission #200517

#TimeUsernameProblemLanguageResultExecution timeMemory
200517a1_NBigger segments (IZhO19_segments)C++14
37 / 100
1589 ms3064 KiB
#include <bits/stdc++.h> #define F first #define S second using namespace std; const int N = 5e5 + 5; int n,a[N]; long long pref[N]; pair<long long,long long> dp[N]; int main(){ ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0); cin >> n; for(int i = 1; i <= n; i++){ cin >> a[i]; pref[i] = pref[i - 1] + a[i]; } dp[1] = {1,a[1]}; for(int i = 2; i <= n; i++){ dp[i] = {dp[i - 1].F,dp[i - 1].S + a[i]}; for(int j = i - 1; j >= 1; j--){ if(pref[i] - pref[j] >= dp[j].S && dp[i].F <= dp[j].F + 1){ dp[i] = {dp[j].F + 1,pref[i] - pref[j]}; break; } } } cout << dp[n].F; 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...