Submission #659490

#TimeUsernameProblemLanguageResultExecution timeMemory
659490perchutsBigger segments (IZhO19_segments)C++17
0 / 100
1 ms316 KiB
#include <bits/stdc++.h> #define all(x) x.begin(), x.end() #define sz(x) (int) x.size() #define endl '\n' #define pb push_back #define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); using namespace std; using ll = long long; using ull = unsigned long long; using ii = pair<int,int>; using iii = tuple<int,int,int>; const int inf = 2e9+1; const int mod = 1e9+7; const int maxn = 3e5+100; template<typename X, typename Y> bool ckmin(X& x, const Y& y) { return (y < x) ? (x=y,1):0; } template<typename X, typename Y> bool ckmax(X& x, const Y& y) { return (x < y) ? (x=y,1):0; } int main(){_ int n;cin>>n; vector<ll>v(n); for(auto&x:v)cin>>x; int ans = 1; ll last = v[0], tmp = 0, ok = 0; for(ll i=1;i<n;++i){ tmp += v[i]; if(tmp>=last){ if(!ok){ int ptr = 1; while(tmp-v[ptr]>=last+v[ptr])tmp -= v[ptr], last += v[ptr], ptr++; ok = 1; } last = tmp, tmp = 0, ++ans; } } cout<<ans<<endl; }
#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...