#include<stdio.h>
long long S[1010000], SS, Res;
int w[1010000];
int n;
int main(){
int i, j;
scanf("%d",&n);
for(i=1;i<=n;i++){
scanf("%d",&w[i]);
S[i]=S[i-1]+w[i];
}
for(i=n;i>=1;i--){
if(w[i] > 0){
SS = 0;
for(j=i-1;j>=0;j--){
if(S[i]<S[j])break;
SS += S[i]-S[j];
}
Res += SS;
i=j+1;
}
}
printf("%lld\n",Res);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
12920 KB |
Output is correct |
2 |
Correct |
0 ms |
12920 KB |
Output is correct |
3 |
Correct |
0 ms |
12920 KB |
Output is correct |
4 |
Correct |
0 ms |
12920 KB |
Output is correct |
5 |
Correct |
0 ms |
12920 KB |
Output is correct |
6 |
Correct |
0 ms |
12920 KB |
Output is correct |
7 |
Correct |
0 ms |
12920 KB |
Output is correct |
8 |
Correct |
0 ms |
12920 KB |
Output is correct |
9 |
Correct |
0 ms |
12920 KB |
Output is correct |
10 |
Correct |
0 ms |
12920 KB |
Output is correct |
11 |
Correct |
0 ms |
12920 KB |
Output is correct |
12 |
Correct |
0 ms |
12920 KB |
Output is correct |
13 |
Correct |
0 ms |
12920 KB |
Output is correct |
14 |
Correct |
0 ms |
12920 KB |
Output is correct |
15 |
Correct |
0 ms |
12920 KB |
Output is correct |
16 |
Correct |
0 ms |
12920 KB |
Output is correct |
17 |
Correct |
0 ms |
12920 KB |
Output is correct |
18 |
Correct |
0 ms |
12920 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
12920 KB |
Output is correct |
2 |
Correct |
0 ms |
12920 KB |
Output is correct |
3 |
Correct |
7 ms |
12920 KB |
Output is correct |
4 |
Correct |
11 ms |
12920 KB |
Output is correct |
5 |
Correct |
15 ms |
12920 KB |
Output is correct |
6 |
Correct |
12 ms |
12920 KB |
Output is correct |
7 |
Correct |
69 ms |
12920 KB |
Output is correct |
8 |
Correct |
177 ms |
12920 KB |
Output is correct |
9 |
Correct |
134 ms |
12920 KB |
Output is correct |