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

#include <bits/stdc++.h>
#define sz 100002
#define pb push_back
#define ff first
#define ss second
#define ll long long
#define P push
#define PQ priority_queue<double, vector<double>, greater<double>> q

#define VEC(n)                                                                 \\
  ll int x;                                                                    \\
  vector<ll int> v;                                                            \\
  for (int i = 0; i < n; i++) {                                                \\
    cin >> x;                                                                  \\
    v.pb(x);                                                                   \\
  }
#define TEST()                                                                 \\
  int test;                                                                    \\
  cin >> test;                                                                 \\
  while (test--)
#define FAST()                                                                 \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL)
using namespace std;
// Upper_bound   auto x=upper_bound(v[a].begin(),v[a].end(),les);les=*x;
// if(x==v[a].end())break; ll int LCM(ll int a,ll int b) { ll int
// gcd=__gcd(a,b);ll int lcm=a*b/gcd;return lcm;} ll int bigmod(ll int b, ll int
// p, ll int m){if(p==0)return 1;if(p%2!=0) return
// b%m*fun(b,p-1,m)%m;if(p%2==0){ ll int res=fun(b,p/2,m);return
// (res%m*res%m)%m;}} void seive() { prime[np++]=2;for(i=3; i<=sz;
// i+=2){if(mark[i]==0){ prime[np++]=i;for(j=i*i; j<=sz; j+=i) mark[j]=1; } }}
// string add(string s1,string s2) {string s;int j=s1.size()-1,c=0,m; for(int
// i=s2.size()-1; i>=0; i--) {if(j>=0)m=s2[i]-'0'+s1[j]-'0'+c;else
// m=s2[i]-'0'+c; if(m>9) { s+=m%10+'0';c=m/10; } else {  c=0;s+=m+'0'; }j--; }
// if(c!=0) {s+=c+'0'; }reverse(s.begin(),s.end());return s;} int pos;string
// mul(int n) {string s;for(int i=0; i<pos; i++) { s+="0"; }pos++;int c=0,m;
// for(int i=s1.size()-1; i>=0; i--) { m=(s1[i]-'0')*n+c;if(m>9) {
// s+=m%10+'0';c=m/10;} else { c=0; s+=m+'0';} }while(c!=0) {
// s+=c%10+'0';c=c/10;}    reverse(s.begin(),s.end());return s;}
ll int n, k, l = 1, r = 1000000005;
vector<ll int> v;
int BS(ll int m) {
  ll int cnt = 0;
  for (ll int i = 0; i < n; i++) {
    cnt += v[i] / m;
    if (v[i] % m == 0)
      cnt--;
  }
  if (cnt > k)
    return 1;
  return 0;
}
int main() {
  FAST();

  cin >> n >> k;
  ll int m;

  for (int i = 0; i < n; i++) {
    cin >> m;
    v.pb(m);
  }

  while (l <= r) {
    m = (l + r) / 2;
    if (BS(m))
      l = m + 1;
    else
      r = m - 1;
  }
  cout << l << endl;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define sz 100002
#define pb push_back
#define ff first
#define ss second
#define ll long long
#define P push
#define PQ priority_queue<double, vector<double>, greater<double>> q

#define VEC(n)                                                                 \\
  ll int x;                                                                    \\
  vector<ll int> v;                                                            \\
  for (int i = 0; i < n; i++) {                                                \\
    cin >> x;                                                                  \\
    v.pb(x);                                                                   \\
  }
#define TEST()                                                                 \\
  int test;                                                                    \\
  cin >> test;                                                                 \\
  while (test--)
#define FAST()                                                                 \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL)
using namespace std;
// Upper_bound   auto x=upper_bound(v[a].begin(),v[a].end(),les);les=*x;
// if(x==v[a].end())break; ll int LCM(ll int a,ll int b) { ll int
// gcd=__gcd(a,b);ll int lcm=a*b/gcd;return lcm;} ll int bigmod(ll int b, ll int
// p, ll int m){if(p==0)return 1;if(p%2!=0) return
// b%m*fun(b,p-1,m)%m;if(p%2==0){ ll int res=fun(b,p/2,m);return
// (res%m*res%m)%m;}} void seive() { prime[np++]=2;for(i=3; i<=sz;
// i+=2){if(mark[i]==0){ prime[np++]=i;for(j=i*i; j<=sz; j+=i) mark[j]=1; } }}
// string add(string s1,string s2) {string s;int j=s1.size()-1,c=0,m; for(int
// i=s2.size()-1; i>=0; i--) {if(j>=0)m=s2[i]-'0'+s1[j]-'0'+c;else
// m=s2[i]-'0'+c; if(m>9) { s+=m%10+'0';c=m/10; } else {  c=0;s+=m+'0'; }j--; }
// if(c!=0) {s+=c+'0'; }reverse(s.begin(),s.end());return s;} int pos;string
// mul(int n) {string s;for(int i=0; i<pos; i++) { s+="0"; }pos++;int c=0,m;
// for(int i=s1.size()-1; i>=0; i--) { m=(s1[i]-'0')*n+c;if(m>9) {
// s+=m%10+'0';c=m/10;} else { c=0; s+=m+'0';} }while(c!=0) {
// s+=c%10+'0';c=c/10;}    reverse(s.begin(),s.end());return s;}
ll int n, k, l = 0, r = 1000000005;
vector<ll int> v;
int BS(ll int m) {
  ll int cnt = 0;
  for (ll int i = 0; i < n; i++) {
    cnt += v[i] / m;
    if (v[i] % m == 0)
      cnt--;
  }
  if (cnt > k)
    return 1;
  return 0;
}
int main() {
  FAST();

  cin >> n >> k;
  ll int m;

  for (int i = 0; i < n; i++) {
    cin >> m;
    v.pb(m);
  }

  while (l < r) {
    m = (l + r) / 2;
    if (BS(m))
      l = m + 1;
    else
      r = m;
  }
  cout << l << endl;
}