QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#621141 | #5435. Clamped Sequence | zhoudashuai | TL | 15ms | 10704kb | Python3 | 670b | 2024-10-08 09:42:09 | 2024-10-08 09:42:10 |
Judging History
answer
import sys
n,d = map(int, sys.stdin.readline().split())
a = list(map(int, sys.stdin.readline().split()))
ls = [0]*n
ans = -1
for j in range(n):
l = a[j]
r = l+d
cnt = 0
for i in range(n):
if a[i] < l: ls[i] = l
elif a[i] > r: ls[i] = r
else: ls[i] = a[i]
for i in range(n-1):
cnt += abs(ls[i]-ls[i+1])
ans = max(cnt, ans)
for j in range(n):
r = a[j]
l = r-d
cnt = 0
for i in range(n):
if a[i] < l: ls[i] = l
elif a[i] > r: ls[i] = r
else: ls[i] = a[i]
for i in range(n-1):
cnt += abs(ls[i]-ls[i+1])
ans = max(cnt, ans)
print(ans)
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 15ms
memory: 10612kb
input:
8 3 3 1 4 1 5 9 2 6
output:
15
result:
ok 1 number(s): "15"
Test #2:
score: 0
Accepted
time: 10ms
memory: 10612kb
input:
2 1 -1000000000 1000000000
output:
1
result:
ok 1 number(s): "1"
Test #3:
score: 0
Accepted
time: 10ms
memory: 10704kb
input:
2 1000000000 -1000000000 1000000000
output:
1000000000
result:
ok 1 number(s): "1000000000"
Test #4:
score: -100
Time Limit Exceeded
input:
5000 10000 -10000 10000 -10000 10000 -10000 10000 -10000 10000 -10000 10000 -10000 10000 -10000 10000 -10000 10000 -10000 10000 -10000 10000 -10000 10000 -10000 10000 -10000 10000 -10000 10000 -10000 10000 -10000 10000 -10000 10000 -10000 10000 -10000 10000 -10000 10000 -10000 10000 -10000 10000 -10...