This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
range = xrange
n, k, d = map(int, raw_input().split())
p = map(int, raw_input().split())
inter = [0]*(k+1)
for i in range(1, k):
inter[i] = p[i] - p[i-1] - 1
inter[0] = p[0] - 1
inter[-1] = n - p[-1]
if d == 1 :
print max(inter[0], inter[-1])
elif d == 2 :
print max(max(inter), inter[0] + inter[-1])
elif d % 2 == 0:
inter[0] += inter.pop()
inter.sort()
inter.reverse()
ans = 0
for i in range(min(d/2, len(inter))):
ans += inter[i]
print ans
else:
ans1, ans2 = 0, 0
ans1 = max(inter[0], inter[-1])
inter1 = inter[1:len(inter)-1]
inter1.sort()
inter1.reverse()
for i in range(min(d/2, len(inter1))):
ans1 += inter1[i]
inter[0] += inter.pop()
inter.sort()
inter.reverse()
for i in range(min(d/2, len(inter))):
ans2 += inter[i]
print max(ans1, ans2)
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |