#include #include using namespace std; using ll = long long; #define rep(i, s, t) for (ll i = s; i < (ll)(t); i++) #define all(x) begin(x), end(x) template bool chmin(T& x, T y) { return x > y ? (x = y, true) : false; } template bool chmax(T& x, T y) { return x < y ? (x = y, true) : false; } void solve() { int n, k; cin >> n >> k; vector a(n); rep(i, 0, n) cin >> a[i]; if ((n + 1) / 2 < k) { cout << "Impossible\n"; return; } vector dp1(k + 1, -1e18); vector dp2(k + 1, -1e18); dp1[0] = dp2[0] = 0; for (int x : a) { auto ndp2 = dp2; rep(i, 0, k + 1) chmax(ndp2[i], dp1[i]); vector ndp1(k + 1, -1e18); rep(i, 0, k) chmax(ndp1[i + 1], dp2[i] + x); swap(dp1, ndp1); swap(dp2, ndp2); } cout << max(dp1[k], dp2[k]) << '\n'; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout << fixed << setprecision(15); int t = 1; // cin >> t; while (t--) solve(); }