#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 5;
const long long INF = 1e18;
int n;
long long A[MAXN];
long long B[MAXN];
long long Pos[MAXN], Neg[MAXN];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n;
for(int i = 1; i <= n; i++)
{
cin >> A[i];
if(i != 1)
{
B[i - 1] = A[i - 1] - A[i];
}
}
for(int i = 1; i <= n; i++)
{
Pos[i] = Pos[i - 1];
if(B[i] >= 0)
{
Pos[i] += (B[i] + 1);
}
}
for(int i = n - 1; i >= 1; i--)
{
Neg[i] = Neg[i + 1];
if(B[i] <= 0)
{
Neg[i] += (1 - B[i]);
}
}
long long ans = INF;
for(int i = 1; i <= n; i++)
{
ans = min(ans, max(Pos[i - 1], Neg[i]));
}
cout << ans << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
25 |
Correct |
1 ms |
336 KB |
Output is correct |
26 |
Correct |
26 ms |
8396 KB |
Output is correct |
27 |
Correct |
29 ms |
8388 KB |
Output is correct |
28 |
Correct |
26 ms |
8456 KB |
Output is correct |
29 |
Correct |
25 ms |
8424 KB |
Output is correct |
30 |
Correct |
26 ms |
7788 KB |
Output is correct |
31 |
Correct |
25 ms |
8524 KB |
Output is correct |
32 |
Correct |
29 ms |
8492 KB |
Output is correct |
33 |
Correct |
24 ms |
8524 KB |
Output is correct |
34 |
Correct |
25 ms |
8404 KB |
Output is correct |
35 |
Correct |
24 ms |
7672 KB |
Output is correct |
36 |
Correct |
25 ms |
7768 KB |
Output is correct |
37 |
Correct |
22 ms |
7788 KB |
Output is correct |
38 |
Correct |
33 ms |
8388 KB |
Output is correct |
39 |
Correct |
25 ms |
8496 KB |
Output is correct |
40 |
Correct |
25 ms |
8436 KB |
Output is correct |
41 |
Correct |
26 ms |
8404 KB |
Output is correct |
42 |
Correct |
25 ms |
8304 KB |
Output is correct |
43 |
Correct |
27 ms |
8476 KB |
Output is correct |
44 |
Correct |
24 ms |
8388 KB |
Output is correct |
45 |
Correct |
25 ms |
8396 KB |
Output is correct |
46 |
Correct |
29 ms |
8504 KB |
Output is correct |
47 |
Correct |
28 ms |
8532 KB |
Output is correct |
48 |
Correct |
25 ms |
8388 KB |
Output is correct |