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>
using namespace std;
#define int long long
void answer(vector<int> arr){
int n = arr.size();
arr.insert(arr.begin(),0);
vector<int> DP(n+1);
for(int i=1;i<=n;i++){
int sum = arr[i-1];
DP[i]=1;
for(int j=i-2;j>=0;j--){
if(sum>arr[i] and sum>arr[j])DP[i]=max(DP[i],DP[j]+2);
sum+=arr[j];
}
}
int ans = DP[n];
int sum = arr[n];
for(int i=n-1;i;i--){
if(arr[i]<sum)ans=max(ans,DP[i]+1);
sum+=arr[i];
}
cout << ans << '\n';
}
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
vector<int> L(n+1);
for(int i=1;i<=n;i++)cin>>L[i];
int q;
cin >> q;
for(int i=1;i<=q;i++){
int x,y,a,b;cin>>x>>y>>a>>b;
L[x]=y;
vector<int> arr;
for(int j=a+1;j<=b;j++){
arr.emplace_back(L[j]);
}
answer(arr);
}
}
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |