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 <iostream>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <iomanip>
#include <cmath>
#include <limits>
#include <map>
#include <utility>
#include <cctype>
#include <string>
#include <cstring>
#include <stack>
#include <queue>
#include<assert.h>
#include <functional>
#include <iterator>
using namespace std;
const int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1};
#define OVL(x,s) for(auto y:x) cout<<y<<s; cout<<"\n";
#ifdef IOI
void dbg_out() { cout << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cout << ' ' << H; dbg_out(T...); }
#define dbg(...) cout << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__);
#else
#define dbg(...) 1337;
#endif
#define endl "\n"
#define pb push_back
#define F first
#define S second
#define ll long long
#define mod 1000000007
#define all(v) v.begin(),v.end()
#define int long long
const int MAXN=5100;
vector<int> v(MAXN);
signed main(){
ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int n;
cin>>n;
for(int i=0;i<n;i++) cin>>v[i];
int ans=0;
int pref[n+1];
memset(pref,0,sizeof(pref));
for(int i=0;i<n;i++){
pref[i]=v[i];
if(i) pref[i]+=pref[i-1];
}
auto sum = [&](int l,int r){
if(l==0) return pref[r];
return pref[r]-pref[l-1];
};
for(int i=0;i<n;i++){
int lst=sum(0,i);
int b=1;
int sum=0;
for(int j=i+1;j<n;j++){
sum+=v[j];
// if(i==1){
// dbg(j,sum,lst,b)
// }
if(sum>=lst){
lst=sum;
b++;
sum=0;
}
}
if(sum>=lst) b++;
// dbg(i,b)
ans=max(ans,b);
}
cout<<ans<<endl;
}
# | 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... |