#include <iostream>
using namespace std;
int abs(int n)
{
if (n < 0)
return n*-1;
return n;
}
int main()
{
int n, factor=0;
long long int sum[100000] = {};
long long int num[100000] = {};
long long int result=0;
cin >> n;
for (int i = 0; i < n; i++)
{
cin >> num[i];
sum[0] += num[i];
}
for (int i = 1; i < n; i++)
sum[i] = sum[i - 1] - num[i - 1];
for (int i = 0; i < n; i++)
{
factor++;
if (num[i] >= 0)
{
result += num[i] * factor;
}
else
{
if (i == n - 1)
break;
if (abs(num[i] * factor) <= sum[i+1] * factor)
result += num[i] * factor;
else
factor = 0;
}
}
cout << result << endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
3152 KB |
Output is correct |
2 |
Incorrect |
1 ms |
3156 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Halted |
0 ms |
0 KB |
- |