Language: C++

#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <numeric>
#include <set>

using namespace std;
struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}

using int64 = long long;

const int MOD = 1000000007;
struct mint {
    int64 x;
    mint(const int64 x1=0) { x = x1%MOD; };

    mint& operator++(int n) { x+=1; return *this; };
    mint& operator--(int n) { x-=1; return *this; };
    mint& operator=(int64 n) { x=n%MOD; return *this; };
    mint& operator--() {x-=1; return *this; };
    mint& operator+=(const mint a) { if ( (x+=a.x) >= MOD) x-=MOD; return *this; }
    mint& operator-=(const mint a) { if ( (x+= MOD-a.x) >= MOD) x-= MOD; return *this; }
    mint& operator*=(const mint a) { (x*=a.x) %= MOD; return *this; }
    mint& operator/=(const mint a) { return (*this) *= a.inv();}
    mint operator+(const mint a) const { mint res(*this); return res+=a; }
    mint operator-(const mint a) const { mint res(*this); return res-=a; }
    mint operator*(const mint a) const { mint res(*this); return res*=a; }
    mint operator/(const mint a) const { mint res(*this); return res/=a; }
    mint inv() const { return pow(MOD-2);}
    friend ostream& operator<<(ostream &os, const mint a) noexcept { return os << a.x; }
    constexpr bool operator == (const mint& r) const noexcept { return this->x == r.x; }
    constexpr bool operator != (const mint& r) const noexcept { return this->x != r.x; }
    mint pow(long long t) const {
        if (!t) return mint(1);
        mint a = pow(t>>1);
        a*=a;
        if(t&1) a*= *this;
        return a;
    }
};

template <typename T> bool chmax(T& a, const T&& b){if(a<b){a=b; return true;} return false;}

int main() {
    int64 n,k;
    cin >> n >> k;
    vector a(n, 0LL);
    for (int i=0; i<n; i++) cin >> a[i];

    auto c = [](const int64& x, const int64& y){return abs(x) > abs(y);};

    int64 zerocnt = count(a.begin(), a.end(), 0LL);
//    debug(zerocnt);
    if (zerocnt > n-k) {
        cout << 0 << endl;
        return 0;
    }
    sort(a.begin(), a.end());

    vector b = a;
    copy(b.begin(), b.end(), back_insert_iterator(a));
    copy(b.begin(), b.end(), back_insert_iterator(a));
    copy(b.begin(), b.end(), back_insert_iterator(a));

    int64 r = 0;
    int64 cnt = 0;
    int64 sum = 0;
    int64 _max = LONG_MIN;

    int64 al = 0 ,ar = 0;
    int64 zero = 0;
    vector<P> lr;
    for (int64 l=0; l<=n*3; l++) {
        if (r < l) r = l;
        while(r<=n*3 && r-l < k) {
            sum += abs(a[r]);
            if (a[r] < 0) cnt++;
            if (a[r] == 0) zero++;
            r++;
        }
        if (r>n*3) break;

        if (zero<=0 && chmax(_max, sum * (cnt%2? -1 : 1))) {
            al = l;
            ar = r-1;
        }
        sum -= abs(a[l]);
        if (a[l]<0) cnt--;
        if (a[l]==0) zero--;
    }

    int64 ans = 1;
    int64 zeroc = 0;
    for (int64 i=al; i<=ar; i++) {
        ans *= a[i];
        ans %= MOD;
        if (a[i] % 2) zeroc++;
    }


    if (zeroc%2 && zerocnt > 0) ans = 0;
    if (ans < 0) ans+=MOD;
    ans %= MOD;

    cout << ans << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:75:18: error: 'LONG_MIN' was not declared in this scope
   75 |     int64 _max = LONG_MIN;
      |                  ^~~~~~~~
a.cc:11:1: note: 'LONG_MIN' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
   10 | #include <set>
  +++ |+#include <climits>
   11 | 
a.cc:79:12: error: 'P' was not declared in this scope
   79 |     vector<P> lr;
      |            ^
a.cc:79:13: error: template argument 1 is invalid
   79 |     vector<P> lr;
      |             ^
a.cc:79:13: error: template argument 2 is invalid