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 <math.h>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <sstream>
#include <set>
using namespace std;
int main()
{
int n;
scanf("%d", &n);
vector<int> val(n);
for (int i=0; i<n; i++)
scanf("%d", &val[i]);
vector<int> mark(n);
long long sum = 0;
for (int i=n-1; i>=0; i--) {
sum = max(sum + val[i], 0LL + val[i]);
if (sum >= 0) mark[i] = 1;
}
long long res = 0;
long long mult = 0;
for (int i=0; i<n; i++) {
if (mark[i]) {
mult ++;
res += mult * val[i];
} else mult = 0;
}
printf("%lld\n", res);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |