# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
344525 | Nurlykhan | Bigger segments (IZhO19_segments) | C++17 | 949 ms | 620 KiB |
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>
#define ll long long
using namespace std;
const int N = (int)5e5 + 10;
const int mod = (int)1e9 + 7;
int n;
int a[N];
ll pref[N];
ll get_sum(int l, int r) {
return pref[r] - pref[l - 1];
}
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
pref[i] = pref[i - 1] + a[i];
}
int ans = 0;
for (int mask = 0; mask < (1 << (n - 1)); mask++) {
vector<int> pos;
pos.push_back(0);
for (int i = 0; i < n - 1; i++) {
if ((mask >> i) % 2) {
pos.push_back(i + 1);
}
}
pos.push_back(n);
bool bad = 0;
for (int i = 0; i + 2 < pos.size(); i++) {
if (get_sum(pos[i], pos[i + 1] - 1) > get_sum(pos[i + 1], pos[i + 2] - 1))
bad = 1;
}
if (!bad)
ans = max(ans, (int)pos.size() - 1);
}
printf("%d", ans);
return 0;
for (int i = 1; i <= n; i++) {
ll cur_sum = 0;
ll prev_sum = get_sum(1, i);
int cnt = 0, j = i + 1;
while (j <= n) {
cur_sum += a[j];
if (cur_sum >= prev_sum) {
prev_sum = cur_sum;
cur_sum = 0;
cnt++;
}
j++;
}
ans = max(ans, cnt + 1);
}
printf("%d", ans);
return 0;
}
Compilation message (stderr)
# | 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... |