Submission #409134

#TimeUsernameProblemLanguageResultExecution timeMemory
4091348e7Bigger segments (IZhO19_segments)C++14
0 / 100
1 ms332 KiB
//Challenge: Accepted #include <iostream> #include <vector> #include <algorithm> #include <utility> #include <stack> #include <set> #define ll long long #define maxn 3005 #define mod 1000000007 #define pii pair<int, int> #define ff first #define ss second #define io ios_base::sync_with_stdio(0);cin.tie(0); using namespace std; ll a[maxn], pref[maxn]; int dp[maxn][maxn]; int solve(int n) { for (int i = 0;i < n;i++) { for (int j = 0;j < n;j++) dp[i][j] = 0; } for (int i = 0;i < n;i++) { for (int j = 0;j <= i;j++) { if (j == 0) { dp[i][j] = 1; } else { for (int k = j - 1;k >= 0;k--) { if (pref[i] - pref[j - 1] >= pref[j - 1] - (k ? pref[k - 1] :0)) { dp[i][j] = max(dp[i][j], dp[j - 1][k] + 1); } } } } } int ret = 0; for (int i = 0;i < n;i++) ret = max(ret, dp[n - 1][i]); return ret; } signed main() { io int n; cin >> n; for (int i = 0;i < n;i++) { cin >> a[i]; pref[i] = a[i] + (i ? pref[i - 1] : 0); } cout << solve(n) << endl; } /* 4 2 3 1 7 5 6 2 3 9 13 3 3 1 2 */
#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...