Problem p02616 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define uu unsigned
#define io                                                                     \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL)
const ll MOD = 1000000007;
#define pi pair<int, int>
#define pl pair<ll, ll>
#define mkp make_pair
#define ss second
#define ff first
#define all(x) x.begin(), x.end()
#define vi vector<int>
#define vl vector<ll>
#define vb vector<bool>
#define pb push_back
#define pf push_front
#define printcas cout << "Case " << cas << ": "
#define _ continue;
#define endl '\\n'
#define __                                                                     \\
  cout << endl;                                                                \\
  continue;
#define vc4d(nam, type, a, b, c, d, fix)                                       \\
  vector<vector<vector<vector<type>>>> nam(                                    \\
      a, vector<vector<vector<type>>>(                                         \\
             b, vector<vector<type>>(c, vector<type>(d, fix))))
const ll oo = (1ll << 60);
const ll mo = -1;
int main() {
  io;
  int T = 1;
  // cin>>T;
  // for(int cas=1;cas<=T;cas++)
  while (T--) {
    ll n, k, i, j, pos = 0, neg = 0;
    cin >> n >> k;
    vl v(n);
    for (ll &x : v) {
      cin >> x;
      if (x >= 0)
        pos++;
    }
    neg = n - pos;
    sort(all(v));
    if (n == k) {
      ll mul = 1;
      for (i = 0; i < neg; i++)
        mul = (mul * (mo * v[i])) % MOD;
      for (; i < n; i++)
        mul = (mul * v[i]) % MOD;
      if (neg & 1)
        mul = MOD - mul;
      cout << mul;
      _
    }
    if (neg == n and (k & 1)) {
      ll mul = 1;
      for (i = n - 1; i > n - k; i -= 2) {
        mul = (mul * (mo * v[i])) % MOD;
        mul = (mul * (mo * v[i - 1])) % MOD;
      }
      v[n - k] *= mo;
      mul = MOD - (mul * v[n - k]) % MOD;
      cout << mul;
      _
    }
    i = max(neg, n - k), j = 0;
    if (k > n - i and (k - (n - i)) & 1)
      i++;
    if (k > n - i)
      j = k - (n - i);
    for (; j < neg - 1 and i < n - 1 and mo * v[j] > v[i]; j += 2) {
      ll a = mo * v[j], b = mo * v[j + 1];
      if (a + b > v[i] + v[i + 1])
        i += 2;
      else if (a + b == v[i] + v[i + 1] and (a - b) < v[i + 1] - v[i])
        i += 2;
      else
        break;
    }
    ll mul = 1;
    for (j--; j > 0; j -= 2) {
      mul = (mul * (mo * v[j])) % MOD;
      mul = (mul * (mo * v[j - 1])) % MOD;
    }
    for (; i < n; i++) {
      mul = (mul * v[i]) % MOD;
    }
    cout << mul;
  }
  return 0;
}


Error: -11

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define uu unsigned
#define io                                                                     \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL)
const uu ll MOD = 1000000007;
#define pi pair<int, int>
#define pl pair<ll, ll>
#define mkp make_pair
#define ss second
#define ff first
#define all(x) x.begin(), x.end()
#define vi vector<int>
#define vl vector<ll>
#define vb vector<bool>
#define pb push_back
#define pf push_front
#define printcas cout << "Case " << cas << ": "
#define _ continue;
#define endl '\\n'
#define __                                                                     \\
  cout << endl;                                                                \\
  continue;
#define vc4d(nam, type, a, b, c, d, fix)                                       \\
  vector<vector<vector<vector<type>>>> nam(                                    \\
      a, vector<vector<vector<type>>>(                                         \\
             b, vector<vector<type>>(c, vector<type>(d, fix))))
const ll oo = (1ll << 60);
const ll mo = -1;
int main() {
  io;
  int T = 1;
  // cin>>T;
  // for(int cas=1;cas<=T;cas++)
  while (T--) {
    uu ll n, k, i, j, pos = 0, neg = 0;
    cin >> n >> k;
    vl v(n);
    for (ll &x : v) {
      cin >> x;
      if (x >= 0)
        pos++;
    }
    neg = n - pos;
    sort(all(v));
    if (neg == n and (k & 1)) {
      uu ll mul = 1;
      for (i = n - 1; i > n - k; i -= 2) {
        mul = (mul * (uu ll)(mo * v[i])) % MOD;
        mul = (mul * (uu ll)(mo * v[i - 1])) % MOD;
      }
      v[n - k] *= mo;
      mul = MOD - (mul * (uu ll)v[n - k]) % MOD;
      cout << mul;
      _
    }
    i = max(neg, n - k), j = 0;
    if (k > n - i and (k - (n - i)) & 1)
      i++;
    if (k > n - i)
      j = k - (n - i);
    for (; j < neg - 1 and i < n - 1 and mo * v[j] > v[i]; j += 2) {
      ll a = mo * v[j], b = mo * v[j + 1];
      if (a + b > v[i] + v[i + 1])
        i += 2;
      else if (a + b == v[i] + v[i + 1] and (a - b) < v[i + 1] - v[i])
        i += 2;
      else
        break;
    }
    uu ll mul = 1;
    for (j--; j > 0; j -= 2) {
      mul = (mul * (uu ll)(mo * v[j])) % MOD;
      mul = (mul * (uu ll)(mo * v[j - 1])) % MOD;
    }
    for (; i < n; i++) {
      mul = (mul * (uu ll)v[i]) % MOD;
    }
    cout << mul;
  }
  return 0;
}