Language: C++

#include <bits/stdc++.h>

using namespace std;

#define countof(a) (sizeof(a)/sizeof(*a))

#define vi vector<int>
#define vvi vector<vector<int> >
#define vpi vector<pi >
#define pi pair<int,int>
#define mp make_pair
#define fi first
#define se second
#define all(n) n.begin(), n.end()

#define FROMTO(var, from, to) for (register int var = (from), var##down = ((int)(to)) < ((int)(from));var##down ? (var >= (int)(to)) : (var <= (int)(to));var##down ? var-- : var++)
#define UPTO(var, from, to)   for (register int var = (from); var <= ((int)to); var++)
#define DOWNTO(var, from, to) for (register int var = (from); var >= ((int)to); var--)
#define FOR(var, to)          UPTO(var, 0, (to)-1)
#define DOWN(var, from)       DOWNTO(var, (from)-1, 0) 

#define INIT(var, val) FOR(i,countof(var)) var[i] = val
#define INPUT(var) FOR(i,countof(var)) cin >> var[i]
#define INPUT1(var) FOR(i,countof(var)) cin >> var[i], var[i]--

#define SORT(v) qsort(v,countof(v),sizeof(*v),int_less)
#define SORTT(v) qsort(v,countof(v),sizeof(*v),int_greater)
#define QSORT(v,b) qsort(v,countof(v),sizeof(*v),b)

typedef uint8_t u8;
typedef uint16_t u16;
typedef uint32_t u32;
typedef uint64_t u64;
typedef int8_t s8;
typedef int16_t s16;
typedef int32_t s32;
typedef int64_t s64;

static const int MOD = 1000000007;
static const int INF = ((1<<30)-1);
static const s64 LINF = ((1LL << 62)-1);

struct Comb {
    vector<vector<s64> > data;
    Comb(int n) { // O(n^2)
        data = vector<vector<s64> >(n+1,vector<s64>(n+1,1));
        UPTO(i,1,n) {
            FOR(j,i+1) {
                if (!j || j == i) data[i][j] = 1;
                else data[i][j] = data[i-1][j-1] + data[i-1][j];
            }
        }
    }
    
    s64 ncr(int n, int r) {
        return data[n][r];
    }
};

static inline int ri() {
  int a;
  scanf("%d", &a);
  return a;
}

int main() {
	int n = ri();
	int k = ri();
	int a[n];
	INPUT(a);
	
	s64 s[n];
	FOR(i,n) s[i] = i?s[i-1]+a[i]:a[i];
	
	s64 ss[n];
	FOR(i,n) ss[i] = i?ss[i-1]+(a[i]<0?0:a[i]):(a[i]<0?0:a[i]);
	
	s64 res = -LINF;
	FOR(i,n) {
		if (i+k > n) break;
		s64 base = max(0LL,s[i+k-1]-s[i-1]);
		if (i) base += ss[i-1];
		base += ss[n-1]-ss[i+k-1];
		res = max(res,base);
	}
	cout << res << endl;
	
	return 0;
}




Compiler output:
a.cc: In constructor 'Comb::Comb(int)':
a.cc:47:14: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   47 |         UPTO(i,1,n) {
      |              ^
a.cc:17:49: note: in definition of macro 'UPTO'
   17 | #define UPTO(var, from, to)   for (register int var = (from); var <= ((int)to); var++)
      |                                                 ^~~
a.cc:48:17: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   48 |             FOR(j,i+1) {
      |                 ^
a.cc:17:49: note: in definition of macro 'UPTO'
   17 | #define UPTO(var, from, to)   for (register int var = (from); var <= ((int)to); var++)
      |                                                 ^~~
a.cc:48:13: note: in expansion of macro 'FOR'
   48 |             FOR(j,i+1) {
      |             ^~~
a.cc: In function 'int main()':
a.cc:23:24: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   23 | #define INPUT(var) FOR(i,countof(var)) cin >> var[i]
      |                        ^
a.cc:17:49: note: in definition of macro 'UPTO'
   17 | #define UPTO(var, from, to)   for (register int var = (from); var <= ((int)to); var++)
      |                                                 ^~~
a.cc:23:20: note: in expansion of macro 'FOR'
   23 | #define INPUT(var) FOR(i,countof(var)) cin >> var[i]
      |                    ^~~
a.cc:70:9: note: in expansion of macro 'INPUT'
   70 |         INPUT(a);
      |         ^~~~~
a.cc:73:13: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   73 |         FOR(i,n) s[i] = i?s[i-1]+a[i]:a[i];
      |             ^
a.cc:17:49: note: in definition of macro 'UPTO'
   17 | #define UPTO(var, from, to)   for (register int var = (from); var <= ((int)to); var++)
      |                                                 ^~~
a.cc:73:9: note: in expansion of macro 'FOR'
   73 |         FOR(i,n) s[i] = i?s[i-1]+a[i]:a[i];
      |         ^~~
a.cc:76:13: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   76 |         FOR(i,n) ss[i] = i?ss[i-1]+(a[i]<0?0:a[i]):(a[i]<0?0:a[i]);
      |             ^
a.cc:17:49: note: in definition of macro 'UPTO'
   17 | #define UPTO(var, from, to)   for (register int var = (from); var <= ((int)to); var++)
      |                                                 ^~~
a.cc:76:9: note: in expansion of macro 'FOR'
   76 |         FOR(i,n) ss[i] = i?ss[i-1]+(a[i]<0?0:a[i]):(a[i]<0?0:a[i]);
      |         ^~~
a.cc:79:13: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   79 |         FOR(i,n) {
      |             ^
a.cc:17:49: note: in definition of macro 'UPTO'
   17 | #define UPTO(var, from, to)   for (register int var = (from); var <= ((int)to); var++)
      |                                                 ^~~
a.cc:79:9: note: in expansion of macro 'FOR'
   79 |         FOR(i,n) {
      |         ^~~
a.cc:81:31: error: no matching function for call to 'max(long long int, s64)'
   81 |                 s64 base = max(0LL,s[i+k-1]-s[i-1]);
      |                            ~~~^~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:81:31: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 's64' {aka 'long int'})
   81 |                 s64 base = max(0LL,s[i+k-1]-s[i-1]);
      |                            ~~~^~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:81:31: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   81 |                 s64 base = max(0LL,s[i+k-1]-s[i-1]);
      |                            ~~~^~~~~~~~~~~~~~~~~~~~~