#include #include using namespace std; const int inf = 1e9 + 5; const int MAXN = 1e5 + 5; int n, k; int a[MAXN]; int prefix[MAXN]; int zeroCount[MAXN]; struct node { int l, r; int maxValue; node *L, *R; node(int l, int r) { this->l = l; this->r = r; this->L = nullptr; this->R = nullptr; } void build(int l, int r) { if(l==r) { this->maxValue = prefix[l]; return; } this->L = new node(l, (l+r)/2); this->R = new node((l+r)/2+1, r); this->L->build(l, (l+r)/2); this->R->build((l+r)/2+1, r); this->maxValue = max(this->L->maxValue, this->R->maxValue); } int query(int ql, int qr) { if(this->l>=ql && this->r<=qr) return this->maxValue; if(this->rl>qr) return -inf; return max(this->L->query(ql, qr), this->R->query(ql, qr)); } }; node *T; int getZeros(int l, int r) { if(l==0) return zeroCount[r]; return zeroCount[r] - zeroCount[l-1]; } int main() { ios::sync_with_stdio(false); cin.tie(NULL); ifstream cin("krasi.in"); ofstream cout("krasi.out"); int answer = -inf; cin >> n >> k; for(int i = 0;i> a[i]; } zeroCount[0] = ((a[0]==0)?1:0); for(int i = 1;ibuild(0, n-1); for(int i = 0;iquery(i, index); if(i!=0) current -= prefix[i-1]; answer = max(answer, current); } cout << answer << '\n'; }