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

#include <bits/stdc++.h>
#define syosu(x) fixed << setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<P, int> pip;
typedef vector<pip> vip;
const int inf = 1 << 30;
const ll INF = 1ll << 60;
const double pi = acos(-1);
const double eps = 1e-8;
const ll mod = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, -1, 0, 1};

int n, k;
vl a, b;

int main() {
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    if (x > 0)
      a.push_back(x);
    if (x < 0)
      b.push_back(-x);
  }
  int n0 = a.size(), n1 = b.size();
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  if (n0 + n1 < k)
    cout << 0 << endl;
  else if (n0 == 0) {
    if (k % 2 == 0) {
      ll t = 1;
      reverse(b.begin(), b.end());
      for (int i = 0; i < k; i++)
        (t *= b[i]) %= mod;
      cout << t << endl;
    } else if (n0 + n1 < n)
      cout << 0 << endl;
    else {
      ll t = mod - 1;
      for (int i = 0; i < k; i++)
        (t *= b[i]) %= mod;
      cout << t << endl;
    }
  } else {
    if (n0 + n1 == k && n1 % 2 == 1) {
      if (n0 + n1 < k)
        cout << 0 << endl;
      else {
        ll t = mod - 1;
        for (int i = 0; i < n0; i++)
          (t *= a[i]) %= mod;
        for (int i = 0; i < n1; i++)
          (t *= b[i]) %= mod;
        cout << t << endl;
      }
      return 0;
    }
    reverse(a.begin(), a.end());
    reverse(b.begin(), b.end());
    int y = min(n1 / 2 * 2, k / 2 * 2), x = k - y;
    while (x + 1 < n0 && y - 2 >= 0 && a[x] * a[x + 1] > b[y - 1] * b[y - 2])
      x += 2, y -= 2;
    ll t = 1;
    for (int i = 0; i < x; i++)
      (t *= a[i]) %= mod;
    for (int i = 0; i < y; i++)
      (t *= b[i]) %= mod;
    cout << t << endl;
  }
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define syosu(x) fixed << setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<P, int> pip;
typedef vector<pip> vip;
const int inf = 1 << 30;
const ll INF = 1ll << 60;
const double pi = acos(-1);
const double eps = 1e-8;
const ll mod = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, -1, 0, 1};

int n, k;
vl a, b;

int main() {
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    if (x > 0)
      a.push_back(x);
    if (x < 0)
      b.push_back(-x);
  }
  int n0 = a.size(), n1 = b.size();
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  if (n0 + n1 < k)
    cout << 0 << endl;
  else if (n0 == 0) {
    if (k % 2 == 0) {
      ll t = 1;
      reverse(b.begin(), b.end());
      for (int i = 0; i < k; i++)
        (t *= b[i]) %= mod;
      cout << t << endl;
    } else if (n0 + n1 < n)
      cout << 0 << endl;
    else {
      ll t = mod - 1;
      for (int i = 0; i < k; i++)
        (t *= b[i]) %= mod;
      cout << t << endl;
    }
  } else {
    if (n0 + n1 == k && n1 % 2 == 1) {
      assert(0);
      if (n0 + n1 < k)
        cout << 0 << endl;
      else {
        ll t = mod - 1;
        for (int i = 0; i < n0; i++)
          (t *= a[i]) %= mod;
        for (int i = 0; i < n1; i++)
          (t *= b[i]) %= mod;
      }
      return 0;
    }
    reverse(a.begin(), a.end());
    reverse(b.begin(), b.end());
    int y = min(n1 / 2 * 2, k / 2 * 2), x = k - y;
    while (x + 1 < n0 && y - 2 >= 0 && a[x] * a[x + 1] > b[y - 1] * b[y - 2])
      x += 2, y -= 2;
    ll t = 1;
    for (int i = 0; i < x; i++)
      (t *= a[i]) %= mod;
    for (int i = 0; i < y; i++)
      (t *= b[i]) %= mod;
    cout << t << endl;
  }
}