QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#621141#5435. Clamped SequencezhoudashuaiTL 15ms10704kbPython3670b2024-10-08 09:42:092024-10-08 09:42:10

Judging History

你现在查看的是最新测评结果

  • [2024-10-08 09:42:10]
  • 评测
  • 测评结果:TL
  • 用时:15ms
  • 内存:10704kb
  • [2024-10-08 09:42:09]
  • 提交

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...

output:


result: