Language: C++

#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define CLEAR(a) memset(a,0,sizeof a)
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define fr freopen("input.txt", "r", stdin);
#define fw freopen("output.txt", "w", stdout);
#define int long long 
typedef long long LL;
typedef pair<int,int> pii;
const int MOD = 1e9 + 7;
const int MAX = 1e5 + 5;
int a[MAX], rghtt[MAX], lfft[MAX], pre[MAX];

 main() {
    //fr;
    int n, k;
    cin >> n >> k;
    FOR(i,1,n) cin >> a[i];

    FOR(i,1,n){
        pre[i] = pre[i-1] + a[i];
        lfft[i] = lfft[i-1] + max(0, a[i]);
    }

    for(int i=n;i>=1;i--){
        rghtt[i] = rghtt[i+1] + max(0, a[i]);
    }
    
    int ret = 0;

    for(int i=1;i<=n-k+1;i++){
        ret = max(ret, lfft[i-1] + max(0,pre[i+k-1]-pre[i-1]) + rghtt[i+k]);
    }
    cout << ret;
    return 0;
}

Compiler output:
a.cc:19:2: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   19 |  main() {
      |  ^~~~
a.cc: In function 'int main()':
a.cc:27:34: error: no matching function for call to 'max(int, long long int&)'
   27 |         lfft[i] = lfft[i-1] + max(0, a[i]);
      |                               ~~~^~~~~~~~~
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:27:34: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   27 |         lfft[i] = lfft[i-1] + max(0, a[i]);
      |                               ~~~^~~~~~~~~
/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:27:34: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   27 |         lfft[i] = lfft[i-1] + max(0, a[i]);
      |                               ~~~^~~~~~~~~
a.cc:31:36: error: no matching function for call to 'max(int, long long int&)'
   31 |         rghtt[i] = rghtt[i+1] + max(0, a[i]);
      |                                 ~~~^~~~~~~~~
/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:31:36: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   31 |         rghtt[i] = rghtt[i+1] + max(0, a[i]);
      |                                 ~~~^~~~~~~~~
/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
/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:31:36: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   31 |         rghtt[i] = rghtt[i+1] + max(0, a[i]);
      |                                 ~~~^~~~~~~~~
a.cc:37:39: error: no matching function for call to 'max(int, long long int)'
   37 |         ret = max(ret, lfft[i-1] + max(0,pre[i+k-1]-pre[i-1]) + rghtt[i+k]);
      |                                    ~~~^~~~~~~~~~~~~~~~~~~~~~~
/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:37:39: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   37 |         ret = max(ret, lfft[i-1] + max(0,pre[i+k-1]-pre[i-1]) + rghtt[i+k]);
      |                                    ~~~^~~~~~~~~~~~~~~~~~~~~~~
/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
/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:37:39: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   37 |         ret = max(ret, lfft[i-1] + max(0,pre[i+k-1]-pre[i-1]) + rghtt[i+k]);
      |                                    ~~~^~~~~~~~~~~~~~~~~~~~~~~