alexjercan/bugnet huggingface dataset:
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  ll a, b, n;
  cin >> a >> b >> n;

  ll max = 0;
  ll x;
  if (n >= b) {
    x = b - 1;
  } else {
    x = n;
  }
  while (x <= n) {
    ll Ax = a * x;
    ll value = Ax / b - a * (x / b);
    if (value > max) {
      max = value;
    }
    break;
  }

  cout << max << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  ll a, b, n;
  cin >> a >> b >> n;

  ll max = 0;
  ll x;
  if (n >= b) {
    x = b - 1;
  } else {
    x = n;
  }
  while (x <= n) {
    ll Ax = a * x;
    ll value = Ax / b - a * (x / b);
    if (value > max) {
      max = value;
    }
    x += b;
  }

  cout << max << endl;

  return 0;
}
Problem p02696 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
// #define rep(i, n) for (ll i = 0; i < (n); ++i)
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) { return fabs(a - b) < DBL_EPSILON; }

std::istream &operator>>(std::istream &in, set<string> &o) {
  string a;
  in >> a;
  o.insert(a);
  return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
  ll a;
  in >> a;
  o.push(a);
  return in;
}

typedef pair<ll, ll> P;

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

// ofstream outfile("log.txt");
// outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0')
// << rank << endl;
//  std::cout << std::bitset<8>(9);
// const ll mod = 1e10;

typedef priority_queue<ll, vector<ll>, greater<ll>> PQ_ASK;

#include <boost/multiprecision/cpp_int.hpp>

namespace mp = boost::multiprecision;

int main() {

  mp::cpp_int a, b, n;

  cin >> a >> b >> n;

  assert(a >= 0);
  assert(b >= 0);

  mp::cpp_int x = min(n, b - 1);
  //    for (mp::cpp_int x = 0; x <= 100; x++) {
  mp::cpp_int now = ((a * x) / b) - a * (x / b);
  assert(now >= 0);
  cout << now << endl;
  //    }
}


Error: -6
terminate called after throwing an instance of 'std::runtime_error'
  what():  konai


Fixed submission:

#include <bits/stdc++.h>

using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
// #define rep(i, n) for (ll i = 0; i < (n); ++i)
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) { return fabs(a - b) < DBL_EPSILON; }

std::istream &operator>>(std::istream &in, set<string> &o) {
  string a;
  in >> a;
  o.insert(a);
  return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
  ll a;
  in >> a;
  o.push(a);
  return in;
}

typedef pair<ll, ll> P;

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

// ofstream outfile("log.txt");
// outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0')
// << rank << endl;
//  std::cout << std::bitset<8>(9);
// const ll mod = 1e10;

typedef priority_queue<ll, vector<ll>, greater<ll>> PQ_ASK;

int main() {

  ll a, b, n;
  cin >> a >> b >> n;

  if (a >= 0 && b >= 0) {
    __throw_runtime_error("konai");
    ll x = min(n, b);
    ll now = (a * x / b) - a * (x / b);
    cout << now << endl;
    ret();
  }
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <iostream>
#include <set>
#include <string>
#include <vector>
using namespace std;

int main() {
  long long A, B, N;

  cin >> A >> B >> N;

  long long m = floor(A * min(N, B - 1) / B) - A * floor(min(N, B - 1) / B);

  cout << m << endl;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <set>
#include <string>
#include <vector>
using namespace std;

int main() {
  long long A, B, N;

  cin >> A >> B >> N;
  long long m = 0;

  for (int i = 0; i <= min(N, B); i++) {
    long long sub = floor(A * i / B) - A * floor(i / B);
    m = max(sub, m);
  }

  cout << m << endl;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <stdio.h>
long long min(long long a, long long b) { return (a < b) ? a : b; }
int main(void) {
  long long A, B, N, x;
  x = scanf("%lld %lld %lld", &A, &B, &N);
  x = min(N, B - 1);
  return printf("%lld", (A * x) / B - (x / B) * A), 0;
}

Error: TLE

Fixed submission:

#include <stdio.h>
long long max(long long a, long long b) { return (a < b) ? b : a; }
long long min(long long a, long long b) { return (max(a, b) == b) ? a : b; }
int main(void) {
  long long A, B, N, x, y, answer = 0;
  x = scanf("%lld %lld %lld", &A, &B, &N);
  for (x = 0; x <= min(N, B - 1); x++) {
    y = (A * x) / B - (x / B) * A;
    answer = max(y, answer);
  }
  return printf("%lld", answer), 0;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;

int main() {
  long long a, b, n;
  cin >> a >> b >> n;

  long long x = 0;
  int cnt = 0;
  long long ret = 0;
  long long tmp = 0;
  int calcresult[a];
  if (n < b - 1) {
    tmp = (a * n) / b - a * (n / b);
    cout << tmp << endl;
    return 0;
  }
  for (int i = 0; i < a; i++) {
    calcresult[i] = 0;
  }
  while (1) {
    cnt += 1;
    x = cnt * b - 1;
    if (x > n) {
      break;
    }
    tmp = (a * x) / b - a * (x / b);
    if (calcresult[tmp] == 1) {
      break;
    }
    calcresult[tmp] = 1;
    if (tmp > ret) {
      ret = tmp;
    }
  }
  cout << ret << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

int main() {
  long long a, b, n;
  cin >> a >> b >> n;

  long long x = 0;
  int cnt = 0;
  long long ret = 0;
  long long tmp = 0;
  if (n < b - 1) {
    tmp = (a * n) / b - a * (n / b);
    cout << tmp << endl;
    return 0;
  }
  while (1) {
    cnt += 1;
    x = cnt * b - 1;
    if (x > n) {
      break;
    }
    tmp = (a * x) / b - a * (x / b);
    if (tmp > ret) {
      ret = tmp;
    }
  }
  cout << ret << endl;
  return 0;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;

int main() {
  long long a, b, n;
  long long temp;
  long long x = 0;
  cin >> a >> b >> n;
  if (a > b) {
    x = min(n, b - 1);
    cout << floor(a * x / b) - a * floor(x / b);
  } else if (a == b) {
    long long one = floor(a * n / b) - a * floor(n / b);
    if (one > 0) {
      cout << one;
    } else {
      cout << 0;
    }
  } else {
    x = min(n, b - 1);
    cout << floor(a * x / b) - a * floor(x / b);
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

int main() {
  long long a, b, n;
  long long temp;
  long long mx = 0;
  cin >> a >> b >> n;
  for (int x = 0; x <= min(b, n); x++) {
    temp = floor(a * x / b) - a * floor(x / b);
    if (temp > mx) {
      mx = temp;
    }
  }
  cout << mx;

  return 0;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  ll A, B, N;
  cin >> A >> B >> N;
  ll ans = 0;
  ll kou;
  kou = min(B - 1, N);
  ans = (A * kou) / B - A * (kou / B);
  cout << ans;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  ll A, B, N;
  cin >> A >> B >> N;
  ll ans = 0;
  ll koa;
  ll kou;
  kou = min(B - 1, N);
  koa = min(B / A - 1, N);
  for (int i = koa; i <= kou; i++) {
    ans = max((A * i) / B - A * (i / B), ans);
  }
  cout << ans;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;

int main() {
  long long int A, B, N;
  cin >> A >> B >> N;

  long long int x = N;
  if (N >= B - 1) {
    x = B - 1;
  }

  long long int ans = A * (x % B) / B;

  cout << ans << endl;

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

int calc(long long int A, long long int B, long long int x) {
  return floor((A * x) / B) - A * floor(x / B);
}

int main() {
  long long int A, B, N;
  cin >> A >> B >> N;

  long long int x = 1, ans = 0;
  for (int i = x; i <= N; ++i) {
    ans = max(ans, (long long int)calc(A, B, i));
  }

  cout << ans << endl;

  return 0;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int a, b, n;
  cin >> a >> b >> n;
  if (min(b, n) == b)
    cout << floor((a * (b - 1)) / b) << endl;
  else
    cout << floor((a * n) / b) << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;

int main() {
  ll a, b, n;
  cin >> a >> b >> n;
  vector<ll> v;
  for (ll i = 1; i <= n; i++) {
    ll ans = floor((a * i) / b) - (a * floor(i / b));
    v.push_back(ans);
  }
  cout << *max_element(v.begin(), v.end()) << endl;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define FOR(i, m, n) for (ll i = m; i < (n); i++)
#define RFOR(i, m, n) for (ll i = (m - 1); i >= 0; i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
// #define print(ele) cout << (ele) << "\\n"
#define print10(ele) cout << fixed << setprecision(10) << (ele) << "\\n"

using namespace std;
typedef long long ll;
typedef vector<int> ivec;
typedef vector<string> svec;
typedef vector<ll> lvec;

const int mod = 1e9 + 7;
const ll INF = 1000000000000000000LL;

void print() { cout << endl; }

template <class Head, class... Tail> void print(Head &&head, Tail &&...tail) {
  cout << head;
  if (sizeof...(tail) != 0)
    cout << " ";
  print(forward<Tail>(tail)...);
}

int main() {
  ll a, b, n;
  cin >> a >> b >> n;
  ll x = n;
  if (x >= b - 1)
    x = b - 1;
  ll ans = a * x / b - a * (x / b);
  print(ans);
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define FOR(i, m, n) for (ll i = m; i < (n); i++)
#define RFOR(i, m, n) for (ll i = (m - 1); i >= 0; i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
// #define print(ele) cout << (ele) << "\\n"
#define print10(ele) cout << fixed << setprecision(10) << (ele) << "\\n"

using namespace std;
typedef long long ll;
typedef vector<int> ivec;
typedef vector<string> svec;
typedef vector<ll> lvec;

const int mod = 1e9 + 7;
const ll INF = 1000000000000000000LL;

void print() { cout << endl; }

template <class Head, class... Tail> void print(Head &&head, Tail &&...tail) {
  cout << head;
  if (sizeof...(tail) != 0)
    cout << " ";
  print(forward<Tail>(tail)...);
}

int main() {
  ll a, b, n;
  cin >> a >> b >> n;
  ll ans = 0;
  ll y = min(a, n);
  for (ll i = n; i >= y - 100; i--) {
    if (i < 0)
      break;
    ll x = floor(a * i / b) - a * floor(i / b);
    ans = max(ans, x);
  }
  print(ans);
  return 0;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cmath>
#include <iostream>
using namespace std;

long long int A, B, N;

int main(void) {
  cin >> A >> B >> N;
  long long int ans = 0;

  if (N < B) {
    ans = floor(A * N / B);
  } else {
    ans = floor(A * (B - 1) / B);
  }
  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <cmath>
#include <iostream>
using namespace std;

long long int A, B, N;

int main(void) {
  cin >> A >> B >> N;
  long long int ans = 0;
  long long int temp = 0;
  if (N < B) {
    ans = floor(A * N / B);
  } else {
    for (int i = B - 1; i <= N; i += B) {
      temp = floor(A * i / B) - A * floor(i / B);
      if (ans < temp)
        ans = temp;
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;

int main() {
  long long a, b, n;
  cin >> a >> b >> n;
  long long x = n;
  if (n >= b - 1)
    x = b - 1;
  long long ans = a * x / b - a * (x / b);
  cout << ans << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int a;
  long long b, n;
  cin >> a >> b >> n;
  long long ans = -1e9;

  for (long long i = n - 1000000000; i <= n; i++) {
    long long left = 0, right = 0;
    left = a * i / b;
    right = i / b;
    ans = max(left - a * right, ans);
  }
  cout << ans << endl;
}
Problem p02696 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
typedef vector<ll> vcl;
#define mod 1000000007
int main() {
  ll a, b, n;
  cin >> a >> b >> n;
  ll z = min(n, b - 1);
  ll ans = a * z / b - a * (z / b);
  cout << ans << endl;
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
typedef vector<ll> vcl;
#define mod 1000000007
int main() {
  int64_t a, b, n;
  cin >> a >> b >> n;
  vcl f(n + 1);
  rep(i, n + 1) f[i] = (a * i / b) - a * (i / b);
  for (int64_t i = 0; i < n; i++) {
    f[i + 1] = max(f[i], f[i + 1]);
  }
  cout << f[n] << endl;
  return 0;
}
Problem p02696 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>

#define INF (int)1e8
#define EPS 1e-10
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define RFOR(i, a, b) for (ll i = (b)-1; i >= (a); i--)
#define REP(i, n) for (ll i = 0; i < (n); i++)
#define RREP(i, n) for (ll i = (n)-1; i >= 0; i--)
#define MIN(a, b) (a > b ? b : a)
#define MAX(a, b) (a > b ? a : b)
#define debug(x) cerr << #x << ": " << x << endl
#define all(a) (a).begin(), (a).end()

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef pair<int, int> PII;

// vector
template <typename T> ostream &operator<<(ostream &s, const vector<T> &v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i];
    if (i < len - 1)
      s << "\\t";
  }
  return s;
}

// 2 dimentional vector
template <typename T>
ostream &operator<<(ostream &s, const vector<vector<T>> &vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
    s << vv[i] << endl;
  }
  return s;
}

ll A, B, N;

ll f(ll x) { return floor(A * x / B) - A * floor(x / B); }

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> A >> B >> N;

  ll ans = 0;
  if (A == B) {
    ans = f(0);
  } else {
    if (N >= B - 1) {
      ans = f(B - 1);
    } else {
      ans = f(N);
    }
  }

  cout << ans << endl;

  return 0;
}


Error: 1

Fixed submission:

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>

#define INF (int)1e8
#define EPS 1e-10
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define RFOR(i, a, b) for (ll i = (b)-1; i >= (a); i--)
#define REP(i, n) for (ll i = 0; i < (n); i++)
#define RREP(i, n) for (ll i = (n)-1; i >= 0; i--)
#define MIN(a, b) (a > b ? b : a)
#define MAX(a, b) (a > b ? a : b)
#define debug(x) cerr << #x << ": " << x << endl
#define all(a) (a).begin(), (a).end()

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef pair<int, int> PII;

// vector
template <typename T> ostream &operator<<(ostream &s, const vector<T> &v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i];
    if (i < len - 1)
      s << "\\t";
  }
  return s;
}

// 2 dimentional vector
template <typename T>
ostream &operator<<(ostream &s, const vector<vector<T>> &vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
    s << vv[i] << endl;
  }
  return s;
}

ll A, B, N;

ll f(ll x) { return floor(A * x / B) - A * floor(x / B); }

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> A >> B >> N;

  ll ans;
  if (A == B) {
    ans = f(0);
  } else if (A > B) {
    ans = f(B - 1);
  } else {
    return 1;
  }

  cout << ans << endl;

  return 0;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define INF (int)1e9
#define endl "\\n"
#define ll long long
#define ull unsigned long long

using namespace std;

int main() {
  ios::sync_with_stdio(false), cin.tie(NULL);

  ll a, b, n;
  cin >> a >> b >> n;

  ll ans = 0;
  ll i = min(b - 1, n);
  ans = max(ans, (a * i) / b - a * (i / b));

  ll to = n / b * b - 1;
  i = to;
  ans = max(ans, (a * i) / b - a * (i / b));

  cout << ans << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define INF (int)1e9
#define endl "\\n"
#define ll long long
#define ull unsigned long long

using namespace std;

int main() {
  ios::sync_with_stdio(false), cin.tie(NULL);

  ll a, b, n;
  cin >> a >> b >> n;

  ll i = min(b - 1, n);
  ll ans = 0;

  while (i < n) {
    ans = max(ans, (a * i) / b - a * (i / b));
    i += b;
    i = min(b, n);
  }

  ans = max(ans, (a * i) / b - a * (i / b));
  cout << ans << endl;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main() {
  ll a, b, n;
  cin >> a >> b >> n;
  if (n % b == 0) {
    n--;
    ll ans = (a * n / b) - a * (n / b);
    cout << max((ll)0, ans) << endl;
  } else {
    ll ans1 = (a * n / b) - a * (n / b);
    n = (n / b) * b;
    n--;
    ll ans = (a * n / b) - a * (n / b);
    cout << max((ll)0, max(ans1, ans)) << endl;
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main() {
  ll a, b, n;
  cin >> a >> b >> n;
  ll ans = 0;
  if (n <= b) {
    if (n % b == 0)
      n--;
    ans = (a * n / b) - a * (n / b);
  } else {
    for (ll i = b - 1; i <= n; i += b) {
      ll fin = (a * i / b) - a * (i / b);
      ans = max(ans, fin);
    }
  }
  cout << ans << endl;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

int main() {
  long long A, B, N;
  std::cin >> A >> B >> N;

  if (N < B) {
    long long ans = A * N / B;
    std::cout << ans << std::endl;
  } else {
    long long x = B - 1;
    long long ans = A * x / B - A * (long long)(x / B);
    std::cout << ans << std::endl;
  }

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

int main() {
  long long A, B, N;
  std::cin >> A >> B >> N;

  if (N < B) {
    long long ans = A * N / B;
    std::cout << ans << std::endl;
  } else {
    long long max = 0;
    for (long long i = A - 1; i < A * B; i += A) {
      long long tmp = A * i / B - A * (long long)(i / B);
      max = max < tmp ? tmp : max;
    }
    std::cout << max << std::endl;
  }

  return 0;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define ll long long
#define ar array
#define nl '\\n'
#define AC                                                                     \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(NULL);
using namespace std;
const int M = 1e9 + 7;
const int N = 2 * 1e5;

ll ans = 0;

int main() {
  AC ll a, b, n;
  cin >> a >> b >> n;
  ll x = min(b - 1, n);
  ans = max(ans, (ll)floor((double)(a * x) / b));

  x = min(n, 2 * b - 1);
  ll test = floor((double)(a * x) / b) - a * (x / b);
  ans = max(ans, test);

  cout << ans << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define ll long long
#define ar array
#define nl '\\n'
#define AC                                                                     \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(NULL);
using namespace std;
const int M = 1e9 + 7;
const int N = 2 * 1e5;

ll ans = 0;

int main() {
  AC ll a, b, n;
  cin >> a >> b >> n;
  ll x = 1;
  while (x < b && x <= n) {
    ans = max(ans, (ll)floor((double)(a * x) / b));
    x++;
  }
  if (x <= n) {
    x = min(n, 2 * b - 1);
    ll test = floor((double)(a * x) / b) - a * (x / b);
    ans = max(ans, test);
  }
  cout << ans << endl;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>

#define ll long long int
#define mod 1000000007

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll a, b, n;
  cin >> a >> b >> n;
  ll range;
  if (n < b)
    cout << a * n / b;
  else
    cout << a * (b - 1) / b;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>

#define ll long long int
#define mod 1000000007

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll a, b, n;
  cin >> a >> b >> n;
  ll range;
  if (n < b)
    range = n;
  else
    range = b - 1;

  ll maxi = 0;
  for (ll i = range; i >= 0; i--) {
    maxi = max(maxi, a * i / b);
  }
  cout << maxi;
}
Problem p02696 (C++) — buggy submission, verdict: Runtime Error

#pragma GCC optimize("Ofast")
#include <algorithm>
#include <stdio.h>
using namespace std;
int main() {
  long long a, b, n;
  scanf("%lld%lld%lld", &a, &b, &n);
  long long x = min(n, b - 1);
  printf("%lld\\n", a * x / b - a * (x / b));
}


Error: -6
4c02531f-edd3-4f19-aea8-98f9b666a074.out: /home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02696/C++/s213138586.cpp:12: int main(): Assertion `len>=2' failed.


Fixed submission:

#pragma GCC optimize("Ofast")
#include <algorithm>
#include <assert.h>
#include <stdio.h>
using namespace std;
bool used[100005] = {0};
int main() {
  int i, n, m, index = 1;
  scanf("%d%d", &n, &m);
  int len = n;
  for (i = 1; i <= m; i++) {
    assert(len >= 2);
    printf("%d %d\\n", index, index + len - 1);
    index++;
    len -= 2;
  }
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int main() {
  long long a, b, n;

  cin >> a >> b >> n;
  if (n >= b)
    cout << a * (b - 1) / b << endl;
  else
    cout << a * n / b << endl; // n < b
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  long long a, b, n;

  cin >> a >> b >> n;
  long long maxi = 0;
  for (int i = 0; i <= n; i++) {
    maxi = max(maxi, (i % b));
  }

  cout << a * maxi / b << endl;
}