Submission #44272

# Submission time Handle Problem Language Result Execution time Memory
44272 2018-03-31T06:33:14 Z leejseo Stove (JOI18_stove) Python 2
100 / 100
205 ms 19020 KB
import sys
c = int(2E9)
raw_input = sys.stdin.readline
range = xrange
N, K = map(int, raw_input().split())
T = [0 for i in range(N) ]
for i in range(N):
    T[i] = int(raw_input())
''' O(NK) code
DP = [ [c]*K for i in xrange(N) ]
DIFF = [0]*N
for i in range(1, N):
    DIFF[i] = T[i] - T[i-1]
for i in range(K):
    DP[0][i] = 1
for i in range(1, N):
    DP[i][0] = T[i] + 1 - T[0]
    for j in range(1, K):
        DP[i][j] = min(DP[i-1][j] + DIFF[i],
                       DP[i-1][j-1] + 1)
print min(DP[N-1])
'''
#### GREEDY APPROACH
#### If we turn-on stove k times,
#### Then, it is equivalent to turn-off stove on k-1 intervals
M = []
for i in range(N-1):
    M.append(T[i] - T[i+1])
M.sort()
ans = T[-1] - T[0] + K
for i in range(K-1):
    ans += M[i]
print ans
# Verdict Execution time Memory Grader output
1 Correct 14 ms 2936 KB Output is correct
2 Correct 13 ms 3068 KB Output is correct
3 Correct 15 ms 3120 KB Output is correct
4 Correct 14 ms 3120 KB Output is correct
5 Correct 13 ms 3120 KB Output is correct
6 Correct 13 ms 3228 KB Output is correct
7 Correct 15 ms 3228 KB Output is correct
8 Correct 18 ms 3228 KB Output is correct
9 Correct 13 ms 3228 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 2936 KB Output is correct
2 Correct 13 ms 3068 KB Output is correct
3 Correct 15 ms 3120 KB Output is correct
4 Correct 14 ms 3120 KB Output is correct
5 Correct 13 ms 3120 KB Output is correct
6 Correct 13 ms 3228 KB Output is correct
7 Correct 15 ms 3228 KB Output is correct
8 Correct 18 ms 3228 KB Output is correct
9 Correct 13 ms 3228 KB Output is correct
10 Correct 18 ms 3264 KB Output is correct
11 Correct 18 ms 3296 KB Output is correct
12 Correct 18 ms 3328 KB Output is correct
13 Correct 19 ms 3480 KB Output is correct
14 Correct 18 ms 3480 KB Output is correct
15 Correct 20 ms 3480 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 2936 KB Output is correct
2 Correct 13 ms 3068 KB Output is correct
3 Correct 15 ms 3120 KB Output is correct
4 Correct 14 ms 3120 KB Output is correct
5 Correct 13 ms 3120 KB Output is correct
6 Correct 13 ms 3228 KB Output is correct
7 Correct 15 ms 3228 KB Output is correct
8 Correct 18 ms 3228 KB Output is correct
9 Correct 13 ms 3228 KB Output is correct
10 Correct 18 ms 3264 KB Output is correct
11 Correct 18 ms 3296 KB Output is correct
12 Correct 18 ms 3328 KB Output is correct
13 Correct 19 ms 3480 KB Output is correct
14 Correct 18 ms 3480 KB Output is correct
15 Correct 20 ms 3480 KB Output is correct
16 Correct 183 ms 11084 KB Output is correct
17 Correct 173 ms 12020 KB Output is correct
18 Correct 179 ms 13096 KB Output is correct
19 Correct 186 ms 14044 KB Output is correct
20 Correct 198 ms 14896 KB Output is correct
21 Correct 192 ms 16048 KB Output is correct
22 Correct 189 ms 16988 KB Output is correct
23 Correct 205 ms 17912 KB Output is correct
24 Correct 205 ms 19020 KB Output is correct