Language: C++

# include <iostream>
# include <algorithm>
#include <array>
# include <cassert>
#include <cctype># include <iostream>
# include <algorithm>
#include <array>
# include <cassert>
#include <cctype>
#include <climits>
#include <numeric>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <tuple>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <chrono>
# include <random>
# include <limits.h>
# include <unordered_map>
# include <unordered_set>
# include <deque>
# include <cstdio>
# include <cstring>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr long long MOD = 1000000000 + 7;
constexpr long long INF = 1e17 - 10;
const double PI = acos(-1);
typedef pair<LL, LL> Pll;
typedef pair<LL, pair<LL, LL>> Ppll;
typedef pair<LL, pair<LL, bitset<100001>>> Pbll;
typedef pair<LL, pair<LL, vector<LL>>> Pvll;
typedef pair<LL, LL> Vec2;
struct Tll { LL first, second, third; };
typedef pair<LL, Tll> Ptll;
#define rep(i,rept) for(LL i=0;i<rept;i++)
#define Mfor(i,mf) for(LL i=mf-1;i>=0;i--)
int dx[4] = { 0, 1, 0, -1 }, dy[4] = { 1, 0, -1, 0 };
struct Edge { LL to, cost; };
LL h, w, n, m, s=INF, k, sum, ans = 0, t[100001], a[100000];
string YES = "YES", Yes = "Yes", NO = "NO", No = "No";
bool flag;
int main() {
	cin >> n >> m;
	t[0] = 0;
	rep(i, n) {
		w = 0;
		cin >> a[i];
		if (a[i] < 0)
			t[i + 1] = -a[i];
		t[i + 1] += t[i];
		if (a[i] > 0)sum += a[i];
		if (i >= m) {
			s = min(s, t[i + 1] - t[i - m + 1]);
		}
		if (a[i] > 0) { h++, k = 0; }
		else if (a[i] < 0) { k++, h = 0; }
		else { k++, h++; }
		if (k == m || h == m)flag = 1;
	}
	cout << (flag == 1 ? sum : sum - s) << endl;
	return 0;
}
#include <climits>
#include <numeric>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <tuple>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <chrono>
# include <random>
# include <limits.h>
# include <unordered_map>
# include <unordered_set>
# include <deque>
# include <cstdio>
# include <cstring>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr long long MOD = 1000000000 + 7;
constexpr long long INF = 1e17 - 10;
const double PI = acos(-1);
typedef pair<LL, LL> Pll;
typedef pair<LL, pair<LL, LL>> Ppll;
typedef pair<LL, pair<LL, bitset<100001>>> Pbll;
typedef pair<LL, pair<LL, vector<LL>>> Pvll;
typedef pair<LL, LL> Vec2;
struct Tll { LL first, second, third; };
typedef pair<LL, Tll> Ptll;
#define rep(i,rept) for(LL i=0;i<rept;i++)
#define Mfor(i,mf) for(LL i=mf-1;i>=0;i--)
int dx[4] = { 0, 1, 0, -1 }, dy[4] = { 1, 0, -1, 0 };
struct Edge { LL to, cost; };
LL h, w, n, m, s=INF, k, sum, ans = 0, t[100001], a[100000];
string YES = "YES", Yes = "Yes", NO = "NO", No = "No";
bool flag;
int main() {
	cin >> n >> m;
	rep(i, n) {
		w = 0;
		cin >> a[i];
		if (a[i] > 0)sum += a[i];
		if (i >= m) {
			rep(j, m) {
				if (a[i - j] <= 0)w -= a[i - j];
			}
			s = min(w, s);
		}
		if (a[i] > 0) { h++, k = 0; }
		else if (a[i] < 0) { k++, h = 0; }
		else { k++, h++; }
		if (k == m || h == m)flag = 1;
	}
	cout << (flag == 1 ? sum : sum - s) << endl;
	return 0;
}

Compiler output:
a.cc:5:18: warning: extra tokens at end of #include directive
    5 | #include <cctype># include <iostream>
      |                  ^
a.cc:102:21: error: redefinition of 'constexpr const long long int MOD'
  102 | constexpr long long MOD = 1000000000 + 7;
      |                     ^~~
a.cc:37:21: note: 'constexpr const long long int MOD' previously defined here
   37 | constexpr long long MOD = 1000000000 + 7;
      |                     ^~~
a.cc:103:21: error: redefinition of 'constexpr const long long int INF'
  103 | constexpr long long INF = 1e17 - 10;
      |                     ^~~
a.cc:38:21: note: 'constexpr const long long int INF' previously defined here
   38 | constexpr long long INF = 1e17 - 10;
      |                     ^~~
a.cc:104:14: error: redefinition of 'const double PI'
  104 | const double PI = acos(-1);
      |              ^~
a.cc:39:14: note: 'const double PI' previously defined here
   39 | const double PI = acos(-1);
      |              ^~
a.cc:110:8: error: redefinition of 'struct Tll'
  110 | struct Tll { LL first, second, third; };
      |        ^~~
a.cc:45:8: note: previous definition of 'struct Tll'
   45 | struct Tll { LL first, second, third; };
      |        ^~~
a.cc:114:5: error: redefinition of 'int dx [4]'
  114 | int dx[4] = { 0, 1, 0, -1 }, dy[4] = { 1, 0, -1, 0 };
      |     ^~
a.cc:49:5: note: 'int dx [4]' previously defined here
   49 | int dx[4] = { 0, 1, 0, -1 }, dy[4] = { 1, 0, -1, 0 };
      |     ^~
a.cc:114:30: error: redefinition of 'int dy [4]'
  114 | int dx[4] = { 0, 1, 0, -1 }, dy[4] = { 1, 0, -1, 0 };
      |                              ^~
a.cc:49:30: note: 'int dy [4]' previously defined here
   49 | int dx[4] = { 0, 1, 0, -1 }, dy[4] = { 1, 0, -1, 0 };
      |                              ^~
a.cc:115:8: error: redefinition of 'struct Edge'
  115 | struct Edge { LL to, cost; };
      |        ^~~~
a.cc:50:8: note: previous definition of 'struct Edge'
   50 | struct Edge { LL to, cost; };
      |        ^~~~
a.cc:116:4: error: redefinition of 'LL h'
  116 | LL h, w, n, m, s=INF, k, sum, ans = 0, t[100001], a[100000];
      |    ^
a.cc:51:4: note: 'LL h' previously declared here
   51 | LL h, w, n, m, s=INF, k, sum, ans = 0, t[100001], a[100000];
      |    ^
a.cc:116:7: error: redefinition of 'LL w'
  116 | LL h, w, n, m, s=INF, k, sum, ans = 0, t[100001], a[100000];
      |       ^
a.cc:51:7: note: 'LL w' previously declared here
   51 | LL h, w, n, m, s=INF, k, sum, ans = 0, t[100001], a[100000];
      |       ^
a.cc:116:10: error: redefinition of 'LL n'
  116 | LL h, w, n, m, s=INF, k, sum, ans = 0, t[100001], a[100000];
      |          ^
a.cc:51:10: note: 'LL n' previously declared here
   51 | LL h, w, n, m, s=INF, k, sum, ans = 0, t[100001], a[100000];
      |          ^
a.cc:116:13: error: redefinition of 'LL m'
  116 | LL h, w, n, m, s=INF, k, sum, ans = 0, t[100001], a[100000];
      |             ^
a.cc:51:13: note: 'LL m' previously declared here
   51 | LL h, w, n, m, s=INF, k, sum, ans = 0, t[100001], a[100000];
      |             ^
a.cc:116:16: error: redefinition of 'LL s'
  116 | LL h, w, n, m, s=INF, k, sum, ans = 0, t[100001], a[100000];
      |                ^
a.cc:51:16: note: 'LL s' previously defined here
   51 | LL h, w, n, m, s=INF, k, sum, ans = 0, t[100001], a[100000];
      |                ^
a.cc:116:23: error: redefinition of 'LL k'
  116 | LL h, w, n, m, s=INF, k, sum, ans = 0, t[100001], a[100000];
      |                       ^
a.cc:51:23: note: 'LL k' previously declared here
   51 | LL h, w, n, m, s=INF, k, sum, ans = 0, t[100001], a[100000];
      |                       ^
a.cc:116:26: error: redefinition of 'LL sum'
  116 | LL h, w, n, m, s=INF, k, sum, ans = 0, t[100001], a[100000];
      |                          ^~~
a.cc:51:26: note: 'LL sum' previously declared here
   51 | LL h, w, n, m, s=INF, k, sum, ans = 0, t[100001], a[100000];
      |                          ^~~
a.cc:116:31: error: redefinition of 'LL ans'
  116 | LL h, w, n, m, s=INF, k, sum, ans = 0, t[100001], a[100000];
      |                               ^~~
a.cc:51:31: note: 'LL ans' previously defined here
   51 | LL h, w, n, m, s=INF, k, sum, ans = 0, t[100001], a[100000];
      |                               ^~~
a.cc:116:40: error: redefinition of 'LL t [100001]'
  116 | LL h, w, n, m, s=INF, k, sum, ans = 0, t[100001], a[100000];
      |                                        ^
a.cc:51:40: note: 'LL t [100001]' previously declared here
   51 | LL h, w, n, m, s=INF, k, sum, ans = 0, t[100001], a[100000];
      |                                        ^
a.cc:116:51: error: redefinition of 'LL a [100000]'
  116 | LL h, w, n, m, s=INF, k, sum, ans = 0, t[100001], a[100000];
      |                                                   ^
a.cc:51:51: note: 'LL a [100000]' previously declared here
   51 | LL h, w, n, m, s=INF, k, sum, ans = 0, t[100001], a[100000];
      |                                                   ^
a.cc:117:8: error: redefinition of 'std::string YES'
  117 | string YES = "YES", Yes = "Yes", NO = "NO", No = "No";
      |        ^~~
a.cc:52:8: note: 'std::string YES' previously declared here
   52 | string YES = "YES", Yes = "Yes", NO = "NO", No = "No";
      |        ^~~
a.cc:117:21: error: redefinition of 'std::string Yes'
  117 | string YES = "YES", Yes = "Yes", NO = "NO", No = "No";
      |                     ^~~
a.cc:52:21: note: 'std::string Yes' previously declared here
   52 | string YES = "YES", Yes = "Yes", NO = "NO", No = "No";
      |                     ^~~
a.cc:117:34: error: redefinition of 'std::string NO'
  117 | string YES = "YES", Yes = "Yes", NO = "NO", No = "No";
      |                                  ^~
a.cc:52:34: note: 'std::string NO' previously declared here
   52 | string YES = "YES", Yes = "Yes", NO = "NO", No = "No";
      |                                  ^~
a.cc:117:45: error: redefinition of 'std::string No'
  117 | string YES = "YES", Yes = "Yes", NO = "NO", No = "No";
      |                                             ^~
a.cc:52:45: note: 'std::string No' previously declared here
   52 | string YES = "YES", Yes = "Yes", NO = "NO", No = "No";
      |                                             ^~
a.cc:118:6: error: redefinition of 'bool flag'
  118 | bool flag;
      |      ^~~~
a.cc:53:6: note: 'bool flag' previously declared here
   53 | bool flag;
      |      ^~~~
a.cc:119:5: error: redefinition of 'int main()'
  119 | int main() {
      |     ^~~~
a.cc:54:5: note: 'int main()' previously defined here
   54 | int main() {
      |     ^~~~