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

#include <bits/stdc++.h>
#define LL long long
#define PII pair<int, int>
#define PIL pair<int, LL>
#define PLI pair<LL, int>
#define PIII pair<int, PII>
#define PLL pair<LL, LL>
#define PLII pair<LL, PII>
#define VI vector<int>
#define VVI vector<VI>
#define VL vector<LL>
#define VVL vector<VL>
#define VPII vector<PII>
#define FF first
#define SS second
#define MP make_pair
#define PB push_back
#define all(x) x.begin(), x.end()
#define watch(x) cout << (#x) << " = " << (x) << '\\n'
#define mset(a, v) memset(a, v, sizeof(a))
#define setp(x) cout << fixed << setprecision(x)
#define EPS 0.00000000001
#define PI acos(-1)
#define loop(i, b, n) for (int i = b; i < n; ++i)
#define rev_loop(i, b, n) for (int i = b; i >= n; --i)
using namespace std;

const int MOD = 1e9 + 7;
const LL MX = 2e9;
const LL INF = 1e9;

int main() {
  // ofstream out("output.txt");
  // ifstream in("input.txt");
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);

  LL n, k;
  cin >> n >> k;
  LL a[n];
  loop(i, 0, n) cin >> a[i];

  LL b = 1, e = MX, mid, ans = -1, k1;
  while (b <= e) {
    mid = (b + e) / 2;
    k1 = 0;
    loop(i, 0, n) {
      k1 += (a[i] / mid);
      if (a[i] % mid == 0)
        --k1;
    }

    // watch(mid); watch(k1);

    if (k1 <= k) {
      ans = mid;
      e = mid - 1;
    } else
      b = mid + 1;
  }

  cout << ans << '\\n';

  /*
  int t,n;
  cin>>t;
  while(t--)
  {
      cin>>n;
      int a[n];
      loop(i,0,n)
      {
          cin>>a[i];
      }
  }
  */

  /*
  int n;
  cin>>n;
  int a[n];
  loop(i,0,n)
  {
      cin>>a[i];
  }
  */

  /*
  cout<<ans<<'\\n';

  if(f) cout<<"YES\\n";
  else cout<<"NO\\n";

  if(f) cout<<"Yes\\n";
  else cout<<"No\\n";
  */

  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define LL long long
#define PII pair<int, int>
#define PIL pair<int, LL>
#define PLI pair<LL, int>
#define PIII pair<int, PII>
#define PLL pair<LL, LL>
#define PLII pair<LL, PII>
#define VI vector<int>
#define VVI vector<VI>
#define VL vector<LL>
#define VVL vector<VL>
#define VPII vector<PII>
#define FF first
#define SS second
#define MP make_pair
#define PB push_back
#define all(x) x.begin(), x.end()
#define watch(x) cout << (#x) << " = " << (x) << '\\n'
#define mset(a, v) memset(a, v, sizeof(a))
#define setp(x) cout << fixed << setprecision(x)
#define EPS 0.00000000001
#define PI acos(-1)
#define loop(i, b, n) for (int i = b; i < n; ++i)
#define rev_loop(i, b, n) for (int i = b; i >= n; --i)
using namespace std;

const int MOD = 1e9 + 7;
const LL MX = 1e9;
const LL INF = 1e9;

int main() {
  // ofstream out("output.txt");
  // ifstream in("input.txt");
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);

  LL n, k;
  cin >> n >> k;
  LL a[n];
  loop(i, 0, n) cin >> a[i];

  LL b = 0, e = MX, mid, ans = -1, k1;
  while (b <= e) {
    mid = (b + e) / 2;
    k1 = 0;
    loop(i, 0, n) { k1 += (a[i] / mid); }

    // watch(mid); watch(k1);

    if (k1 <= k) {
      ans = mid;
      e = mid - 1;
    } else
      b = mid + 1;
  }

  cout << ans << '\\n';

  /*
  int t,n;
  cin>>t;
  while(t--)
  {
      cin>>n;
      int a[n];
      loop(i,0,n)
      {
          cin>>a[i];
      }
  }
  */

  /*
  int n;
  cin>>n;
  int a[n];
  loop(i,0,n)
  {
      cin>>a[i];
  }
  */

  /*
  cout<<ans<<'\\n';

  if(f) cout<<"YES\\n";
  else cout<<"NO\\n";

  if(f) cout<<"Yes\\n";
  else cout<<"No\\n";
  */

  return 0;
}