QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#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)
詳細信息
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...