This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#ifdef LOCAL
#include "/home/trcmai/code/tools.h"
#define debug(x...) cerr << "\e[91m"<<__func__<<":"<<__LINE__<<" [" << #x << "] = ["; _print(x); cerr << "\e[39m" << endl;
#else
#define debug(x...)
#endif
using namespace std;
#define all(a) a.begin(), a.end()
#define ll long long
#define endl '\n'
const int N = 1e6 + 6, LOG = 27, MOD = 1e9 + 7;
const ll INF = 1e18;
int n;
ll a[N];
signed main() {
cin.tie(0)->sync_with_stdio(0);
auto solver=[&](){
cin>>n;
for(int i = 1;i <= n;++i){
cin>>a[i];
a[i] += a[i - 1];
}
/*
dp[i] la max group tai vi tri thu i
opt[i] la min sum cua nhom chua vi tri thu i
dp[i] = dp[j - 1] + 1 voi j = vi tri gan nhat ma opt[j - 1] <= sum[i..j]
*/
vector<ll>dp(n + 1),opt(n + 1);
for(int i = 1;i <= n;++i){
for(int j = i;j >= 1;--j){
ll sum = a[i] - a[j - 1];
if(opt[j - 1] <= sum){
dp[i] = dp[j - 1] + 1;
opt[i] = sum;
break;
}
}
}
cout<<dp[n]<<endl;
};
int t = 1; // cin>>t;
while (t--) solver();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |