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 <stdio.h>
long long int item[1000000];
int check[1000000];
int main()
{
int n, i;
long long int result = 0;
scanf("%d", &n);
for ( i = 0; i < n; i++ )
scanf("%lld", &item[i]);
i = n-1;
while ( i >= 0 ) {
long long int sum = 0;
while ( i >= 0 && item[i] <= 0 )
i--;
while ( i >= 0 && sum + item[i] > 0 ) {
check[i] = 1;
sum += item[i--];
}
}
for ( i = 0; i < n; i++ ) {
int cnt = 1;
while ( i < n && check[i] == 1 )
result += item[i++] * cnt++;
}
printf("%lld\n", result);
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |