Submission #1312194

#TimeUsernameProblemLanguageResultExecution timeMemory
1312194roblukanFeast (NOI19_feast)C++20
Compilation error
0 ms0 KiB
import sys

input = sys.stdin.readline

N, K = map(int, input().split())
A = list(map(int, input().split()))

def solve_opt(l):
    dp = [tuple()] * 2  
    dp[0] = (0, 0)
    dp[1] = (A[0] - l, -1)
    for i in range(1, N):
        tmp0 = max(dp)
        tmp1 = max(
            (dp[0][0] - l + A[i], dp[0][1] - 1),
            (dp[1][0] + A[i], dp[1][1])
        )
        dp[0] = tmp0
        dp[1] = tmp1
    return max(dp)

lo = 0
hi = int(3e14)
while lo < hi:
    mid = (lo + hi) // 2
    res = solve_opt(mid)
    k_prime = -res[1]
    if k_prime > K:
        lo = mid+1
    else:
        hi = mid
res = solve_opt(lo)
print(res[0] + K * lo)

Compilation message (stderr)

feast.cpp:1:1: error: 'import' does not name a type
    1 | import sys
      | ^~~~~~
feast.cpp:1:1: note: C++20 'import' only available with '-fmodules-ts', which is not yet enabled with '-std=c++20'