#include <bits/stdc++.h>
#define file ""
#define all(x) x.begin(), x.end()
#define sc second
#define fr first
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int inf = 1e9;
const int MOD = 1e9 + 7;
int main()
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
vector<ll> a(n + 1);
vector<ll> pref(n + 1);
for (int i = 1; i <= n; i++)
cin >> a[i];
for (int i = 1; i <= n; i++)
pref[i] = pref[i - 1] + a[i];
vector<pair<ll, ll>> d(n + 1);
map<ll, pair<ll, ll>> ans;
vector<ll> all;
for (int i = 1; i <= n; i++) {
auto x = upper_bound(all.begin(), all.end(), pref[i]) - all.begin();
if (x == 0) {
if (all.empty() || (ans[all.back()].fr == 1 && ans[all.back()].sc < pref[i])) {
all.pb(2 * pref[i]);
ans[2 * pref[i]].fr = 1;
ans[2 * pref[i]].sc = pref[i];
}
continue;
}
x--;
d[i].fr = ans[all[x]].fr + 1;
d[i].sc = pref[i] - ans[all[x]].sc;
if (ans[all.back()].fr < d[i].fr || (ans[all.back()].fr == d[i].fr && ans[all.back()].sc < d[i].sc)) {
all.pb(d[i].sc + pref[i]);
ans[d[i].sc + pref[i]].fr = max(d[i].fr, ans[d[i].sc + pref[i]].fr);
ans[d[i].sc + pref[i]].sc = max(pref[i], ans[d[i].sc + pref[i]].sc);
}
}
cout << ans[all.back()].fr;
return false;
}
Compilation message
segments.cpp:22:5: error: expected initializer before 'ios_base'
ios_base::sync_with_stdio(false);
^~~~~~~~
segments.cpp:23:4: error: 'cin' does not name a type; did you mean 'sin'?
cin.tie(nullptr);
^~~
sin
segments.cpp:25:4: error: 'cin' does not name a type; did you mean 'sin'?
cin >> n;
^~~
sin
segments.cpp:28:4: error: expected unqualified-id before 'for'
for (int i = 1; i <= n; i++)
^~~
segments.cpp:28:20: error: 'i' does not name a type
for (int i = 1; i <= n; i++)
^
segments.cpp:28:28: error: 'i' does not name a type
for (int i = 1; i <= n; i++)
^
segments.cpp:30:4: error: expected unqualified-id before 'for'
for (int i = 1; i <= n; i++)
^~~
segments.cpp:30:20: error: 'i' does not name a type
for (int i = 1; i <= n; i++)
^
segments.cpp:30:28: error: 'i' does not name a type
for (int i = 1; i <= n; i++)
^
segments.cpp:35:4: error: expected unqualified-id before 'for'
for (int i = 1; i <= n; i++) {
^~~
segments.cpp:35:20: error: 'i' does not name a type
for (int i = 1; i <= n; i++) {
^
segments.cpp:35:28: error: 'i' does not name a type
for (int i = 1; i <= n; i++) {
^
segments.cpp:54:4: error: 'cout' does not name a type; did you mean 'cosl'?
cout << ans[all.back()].fr;
^~~~
cosl
segments.cpp:55:5: error: expected unqualified-id before 'return'
return false;
^~~~~~
segments.cpp:56:1: error: expected declaration before '}' token
}
^