Submission #502948

#TimeUsernameProblemLanguageResultExecution timeMemory
502948Vladth11Bigger segments (IZhO19_segments)C++14
37 / 100
1583 ms3388 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define debug(x) cerr << #x << " " << x << "\n" #define debugs(x) cerr << #x << " " << x << " " using namespace std; using namespace __gnu_pbds; typedef long long ll; typedef pair <ll, ll> pii; typedef pair <long double, pii> muchie; const ll NMAX = 500001; const ll VMAX = 21; const ll INF = 1e9; const ll MOD = 1000000007; const ll BLOCK = 318; const ll base = 31; const ll nr_of_bits = 21; ll s[NMAX]; ll v[NMAX]; pii dp[NMAX]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, i; cin >> n; for(i = 1; i <= n; i++) cin >> v[i]; for(i = 1; i <= n; i++) s[i] = s[i - 1] + v[i]; for(i = 1; i <= n; i++){ for(int j = 1; j <= i; j++){ if(s[i] - s[j - 1] >= dp[j - 1].second){ if(dp[j - 1].first + 1 > dp[i].first) dp[i] = {dp[j - 1].first + 1, s[i] - s[j - 1]}; else if(dp[j - 1].first + 1 == dp[i].first && (s[i] - s[j - 1]) < dp[i].second){ dp[i] = {dp[j - 1].first + 1, s[i] - s[j - 1]}; } } } } cout << dp[n].first; 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...