#include <bits/stdc++.h>
#define ll long long
#define KAGAMINE ios_base::sync_with_stdio(false);
#define LEN cin.tie(NULL);
#define slv solve();
#define slve int tc = 1; cin >> tc; while(tc--){solve();}
#define pls cout << "mantap\n";
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define pb push_back
#define vector2d(x) vector<vector<x>>
#define pii pair<int, int>
#define pl pair<ll, ll>
const ll inf = 1e9+7;
using namespace std;
ll n;
vector<ll> ar;
vector<ll> wow(5e5+1, -1);
ll solve(ll i, ll sum, ll bef){
if (i == n) return 0;
if (wow[i] != -1) return wow[i];
if (sum < bef){
return wow[i] = solve(i+1, sum+ar[i], bef);
}
else {
return wow[i] = max(solve(i+1, sum+ar[i], bef), 1+solve(i+1, ar[i], sum));
}
return wow[i];
}
int main(){
KAGAMINE LEN
cin >> n;
for (ll i = 0; i < n; i++){
ll tmp; cin >> tmp;
ar.pb(tmp);
}
cout << solve(0, ar[0], 0);
return 0;
}
# | 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... |