#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include //#include #define fi first #define se second #define rep(i,n) for(ll i=0;i<(n);i++) #define rrep(i,n) for(ll i=(n)-1;i>=0;i--) #define orep(i,n) for(ll i=1;i<=(n);i++) #define nfor(i,s,n) for(ll i=(s);i<(n);i++) #define dfor(i,s,n) for(ll i=(s)-1;i>=n;i--) #define INF 2000000000000000000//9223372036854775807 #define all(a) a.begin(),a.end() #define rall(a) a.rbegin(),a.rend() #define chmax(x,y) x = max(x,y) #define chmin(x,y) x = min(x,y) #define pb push_back #define pob pop_back #define vc vector #define for_sz(s) (long long)(s.size()) #define YES cout << "Yes" << endl; #define NO cout << "No" << endl; #define YN {cout << "Yes" << endl;}else{cout << "No" << endl;} #define dame cout << -1 << endl; #define vc_unique(v) v.erase(unique(v.begin(), v.end()), v.end()) #define vc_remove(v,x) v.erase(remove(v.begin(), v.end(),x), v.end()) #define vc_rotate(v) rotate(v.begin(), v.begin()+1, v.end()) #define pop_cnt(s) ll(popcount(uint64_t(s))) #define next_p(v) next_permutation(v.begin(),v.end()) #ifndef ONLINE_JUDGE #define _GLIBCXX_DEBUG #endif using namespace std; //using namespace atcoder; using ll = long long; using ull = unsigned long long; using ld = long double; using pll = pair; using vvvvvl = vector > > > >; using vvvvl = vector > > >; using vvvl = vector > >; using vvl = vector >; using vl = vector; using vb = vector; using vvb = vector >; using Graph = vector >; template using pq = priority_queue,less >; template using pq_g = priority_queue,greater >; ll dx[4] = {0,1,0,-1};ll ddx[8] = {1,1,0,-1,-1,-1,0,1}; ll dy[4] = {1,0,-1,0};ll ddy[8] = {0,1,1,1,0,-1,-1,-1}; bool out_grid(ll i, ll j, ll h, ll w){//trueならcontinueする return(!(0 <= i && i < h && 0 <= j && j void cutoutV(vc> &G, ll H, ll W, ll mx, ll Mx, ll my, ll My){ if(!(0 <= mx && mx < H && 0 < Mx && Mx <= H && mx < Mx))return; if(!(0 <= my && my < H && 0 < My && My <= H && my < My))return; rep(i,Mx - mx)rep(j,My - my){ G[i][j] = G[i + mx][j + my]; } G.resize(Mx - mx, vc(My - my)); return; } ll modpow(ll x,ll y,ll m){ ll a = x; a %= m; ll cnt = 0; ll ans = 1; while(y > 0){ if((1ll << cnt) & y){ y ^= (1ll << cnt); ans *= a; ans %= m; } a = a*a; a %= m; cnt++; } return ans; } ll npow(ll x,ll y){ ll a = x; ll cnt = 0; ll ans = 1; while(y > 0){ if((1ll << cnt) & y){ y ^= (1ll << cnt); ans *= a; } a = a*a; cnt++; } return ans; } struct Edge { ll to; ll cost; }; ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;} ll lcm(ll a, ll b) { return a/gcd(a,b)*b;} // ai+bj=g // ai+bj=gcd(a,b)なるi,jを求める ll extgcd(ll a, ll b, ll& i, ll& j) { if (b == 0) { i = 1; j = 0; return a;} ll p = a/b, g = extgcd(b,a-b*p,j,i); j -= p*i; return g; } vl topological_sort(const vvl& G){ ll N = (ll)G.size(); vl indeg(N, 0), order; queue que; rep(u, N){ for(ll v : G[u]) indeg[v]++; } rep(i, N){ if(indeg[i] == 0) que.push(i); } while(!que.empty()){ ll u = que.front(); que.pop(); order.pb(u); for(ll v : G[u]){ indeg[v]--; if(indeg[v] == 0) que.push(v); } } return order; } ll MOD = 998244353; void print(ld x){printf("%.20Lf\n", x);} //using mint = modint998244353; //////////////////////////////////////////////////////////////// int main(){ ll N,K; cin >> N >> K; vl A(N); rep(i,N)cin >> A[i]; vvvl dp(N+1,vvl(K+1,vl(2,-INF))); dp[0][0][0] = 0; rep(i,N)rep(j,K+1){ if(dp[i][j][0] != -INF)chmax(dp[i+1][j][0],dp[i][j][0]); if(dp[i][j][1] != -INF)chmax(dp[i+1][j][0],dp[i][j][1]); if(j+1 <= K && dp[i][j][0] != -INF)chmax(dp[i+1][j+1][1],dp[i][j][0] + A[i]); } if(dp[N][K][0] == -INF && dp[N][K][1] == -INF){ cout << "Impossible" << endl; return 0; } cout << max(dp[N][K][0],dp[N][K][1]) << endl; }