#include // O(NK) 解法 [[nodiscard]] static inline constexpr uint_fast64_t solve(const uint_fast32_t N, const uint_fast32_t K, const std::vector& A, const std::vector& B) noexcept { std::vector> dp(K + 1, { 0, 0 }); for (uint_fast32_t j = K; j > 0; --j) dp[j] = { A[0], B[0] }; dp[0] = { A[0], 0 }; for (uint_fast32_t i = 1; i < N; ++i) { for (uint_fast32_t j = K; j > 0; --j) dp[j] = { std::max(dp[j][0], dp[j - 1][1]) + A[i], std::max(dp[j - 1][0], dp[j][1]) + B[i] }; dp[0] = { dp[0][0] + A[i], 0 }; } return std::max(dp[K][0], dp[K][1]); } int main() { std::cin.tie(nullptr); std::ios::sync_with_stdio(false); uint_fast32_t N, K; std::cin >> N >> K; std::vector A(N), B(N); for (auto& a : A) std::cin >> a; for (auto& b : B) std::cin >> b; std::cout << solve(N, K, A, B) << '\n'; return 0; }