#include #define endl '\n' #define TRACE(x) cerr << #x << " = " << x << endl #define SZ(x) ((int)x.size()) #define ALL(x) x.begin(), x.end() #define pb push_back #define eb emplace_back #define L_B lower_bound #define U_B upper_bound //#define LOCAL using namespace std; template inline bool chkmax(T &x, const T1 &y) { return x < y ? x = y, true : false; } template inline bool chkmin(T &x, const T1 &y) { return x > y ? x = y, true : false; } const int MAXN = (int)1e5; int n, k; int a[MAXN]; void read() { cin >> n >> k; for (int i = 0; i < n; i++) cin >> a[i]; } int nxt[MAXN]; void solve() { int uk = n - 1; for (int i = n - 1; i >= 0; i--) { if (!a[i]) uk = i; else nxt[i] = uk; } int ans = 0; for (int i = 0; i < n; i++) { if (!a[i]) continue; if (i && nxt[i] == nxt[i - 1]) continue; int curr = a[i], zeros = 0, pr = a[i]; for (int j = i + 1; j < n; j++) { if (!a[j]) { zeros++; if (zeros > k) break; continue; } int now = max(a[j], pr + a[j]); chkmax(curr, now); chkmax(ans, curr); pr = now; } } cout << ans << endl; } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); #ifndef LOCAL freopen("krasi.in", "rt", stdin); freopen("krasi.out", "wt", stdout); #endif // LOCAL read(); solve(); return EXIT_SUCCESS; }