alexjercan/bugnet huggingface dataset:
Problem p02696 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <vector>
#define REP(i, n) for ((i) = 0; (i) < (int)(n); (i)++)
#define ll long long
using namespace std;

ll i, j, k;
const ll MOD = 1000000000 + 7;

ll gcd(ll a, ll b) {
  if (a % b == 0) {
    return (b);
  } else {
    return (gcd(b, a % b));
  }
}

ll lcm(ll a, ll b) { return a * b / gcd(a, b); }

int main() {
  ll a, b, n;
  cin >> a >> b >> n;
  ll ans = 0;
  ans = a * min(b - 1, n) / b;
  cout << ans << '\\n';

  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <vector>
#define REP(i, n) for ((i) = 0; (i) < (int)(n); (i)++)
#define ll long long
using namespace std;

ll i, j, k;
const ll MOD = 1000000000 + 7;

ll gcd(ll a, ll b) {
  if (a % b == 0) {
    return (b);
  } else {
    return (gcd(b, a % b));
  }
}

ll lcm(ll a, ll b) { return a * b / gcd(a, b); }

int main() {
  ll a, b, n;
  cin >> a >> b >> n;
  ll ans = 0;
  ll term = b / gcd(a, b);
  vector<ll> A;
  if (n < term) {
    REP(i, n) {
      ll tmp = (i + 1) * a / b - a * ((i + 1) / b);
      A.push_back(tmp);
    }
    ans = *max_element(A.begin(), A.end());

  } else {
    REP(i, term) {
      ll tmp = (i + 1) * a / b - a * ((i + 1) / b);
      A.push_back(tmp);
    }
    if (A[0] < A.back()) {
      ans = *max_element(A.begin(), A.end()) * (n / term) +
            *max_element(A.begin(), A.begin() + n % term);
    } else {
      ans = *max_element(A.begin(), A.end());
    }
  }
  cout << ans << '\\n';

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

#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(false), cin.tie(0)
#define debug(a) cout << #a ": " << a << endl
using namespace std;
typedef long long ll;
const double eps = 1e-9;
ll a, b, n;
inline ll calc(ll x) { return a * x / b - a * (x / b); }
int main(void) {
  IOS;
  cin >> a >> b >> n;
  if (n <= b) {
    cout << calc(min(n, b - 1)) << endl;
    return 0;
  }
  ll l = b + 1, r = n, ans = b;
  while (l < r - 10) {
    ll m1 = (l + r) >> 1;
    ll m2 = (m1 + r) >> 1;
    if (calc(m1) > calc(m2)) {
      ans = m1;
      r = m2 - 1;
    } else {
      l = m1 + 1;
    }
  }
  for (ll i = l; i <= r; ++i) {
    if (calc(i) > calc(ans))
      ans = i;
  }
  cout << max(calc(ans), calc(b - 1)) << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(false), cin.tie(0)
#define debug(a) cout << #a ": " << a << endl
using namespace std;
typedef long long ll;
const double eps = 1e-9;
ll a, b, n;
ll calc(ll x) { return a * x / b - a * (x / b); }
int main(void) {
  IOS;
  cin >> a >> b >> n;
  ll l = 1, r = n, ans = 1;
  while (l < r - 50) {
    ll m1 = (l + r) >> 1;
    ll m2 = (m1 + r) >> 1;
    if (calc(m1) > calc(m2)) {
      ans = m1;
      r = m2 - 1;
    } else {
      l = m1 + 1;
    }
  }
  for (int i = l; i <= r; ++i) {
    if (calc(i) > calc(ans))
      ans = i;
  }
  cout << calc(ans) << endl;
  return 0;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>    // bitset
#include <cctype>    // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <cstdint> // int64_t, int*_t
#include <cstdio>  // printf
#include <cstring>
#include <deque>    // deque
#include <iostream> // cout, endl, cin
#include <map>      // map
#include <numeric>
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <string>        // string, to_string, stoi
#include <tuple>         // tuple, make_tuple
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <utility>       // pair, make_pair
#include <vector>        // vector
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef unsigned long long ll;

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

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

Error: TLE

Fixed submission:

#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>    // bitset
#include <cctype>    // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <cstdint> // int64_t, int*_t
#include <cstdio>  // printf
#include <cstring>
#include <deque>    // deque
#include <iostream> // cout, endl, cin
#include <map>      // map
#include <numeric>
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <string>        // string, to_string, stoi
#include <tuple>         // tuple, make_tuple
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <utility>       // pair, make_pair
#include <vector>        // vector
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef unsigned long long ll;

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

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

int main(void) {
  long long a, b, n;
  cin >> a >> b >> n;
  long long res;
  if (n / b == 0)
    res = a * n / b - a * (n / b);
  else
    res = a * (n / b * b - 1) / b - a * ((n / b * b - 1) / b);
  cout << res << endl;
  return 0;
}


Error: TLE

Fixed submission:

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

int main(void) {
  long long a, b, n;
  cin >> a >> b >> n;
  long long x = n, res = 0, lim = b / a;
  while (x > lim)
    res = max(res, a * x / b - a * (x / b)), --x;
  cout << res << endl;
  return 0;
}
Problem p02696 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

#define REP(i, a, b) for (int i = a; i < (int)b; i++)
#define rep(i, n) REP(i, 0, n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a)                                                               \\
  { std::cout << #a << " = " << a << "\\n"; }
template <class T1, class T2> inline bool minimize(T1 &a, T2 b) {
  return b < a && (a = b, 1);
}
template <class T1, class T2> inline bool maximize(T1 &a, T2 b) {
  return a < b && (a = b, 1);
}
template <class T, class V> istream &operator>>(istream &ist, pair<T, V> &p) {
  return ist >> p.first >> p.second;
}
template <class T> ostream &operator<<(ostream &ost, pair<T, T> &p) {
  return ost << p.first << ", " << p.second;
}
template <class T> istream &operator>>(istream &ist, vector<T> &vs) {
  for (auto &e : vs)
    ist >> e;
  return ist;
}

typedef long long ll;
int const inf = INT_MAX / 2;

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

int main() {
  ll A, B, N;
  cin >> A >> B >> N;
  cout << f(A, B, min(B - 1, N)) << "\\n";
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

#define REP(i, a, b) for (int i = a; i < (int)b; i++)
#define rep(i, n) REP(i, 0, n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a)                                                               \\
  { std::cout << #a << " = " << a << "\\n"; }
template <class T1, class T2> inline bool minimize(T1 &a, T2 b) {
  return b < a && (a = b, 1);
}
template <class T1, class T2> inline bool maximize(T1 &a, T2 b) {
  return a < b && (a = b, 1);
}
template <class T, class V> istream &operator>>(istream &ist, pair<T, V> &p) {
  return ist >> p.first >> p.second;
}
template <class T> ostream &operator<<(ostream &ost, pair<T, T> &p) {
  return ost << p.first << ", " << p.second;
}
template <class T> istream &operator>>(istream &ist, vector<T> &vs) {
  for (auto &e : vs)
    ist >> e;
  return ist;
}

typedef long long ll;
int const inf = INT_MAX / 2;

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

int main() {
  ll A, B, N;
  cin >> A >> B >> N;
  cout << f(A, B - 1, N) << "\\n";
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;

#define PB push_back
#define MP make_pair
#define F first
#define S second

template <typename T, typename U> bool chmax(T &max, const U &x) {
  if (max < x) {
    max = x;
    return true;
  }
  return false;
}

template <typename T, typename U> bool chmin(T &min, const U &x) {
  if (min > x) {
    min = x;
    return true;
  }
  return false;
}

int main() {
  ll a, b, n;
  cin >> a >> b >> n;
  if (n >= b) {
    cout << (a * (b - 1) / b) - a * ((b - 1) / b);
  } else {
    cout << (a * n / b) - a * (n / b);
  }
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;

#define PB push_back
#define MP make_pair
#define F first
#define S second

template <typename T, typename U> bool chmax(T &max, const U &x) {
  if (max < x) {
    max = x;
    return true;
  }
  return false;
}

template <typename T, typename U> bool chmin(T &min, const U &x) {
  if (min > x) {
    min = x;
    return true;
  }
  return false;
}

int main() {
  ll a, b, n, ans = -INF;
  cin >> a >> b >> n;
  for (ll i = n - 1200000000; i <= n; i++) {
    if (i < 0)
      continue;
    chmax(ans, floor(a * i / b) - a * floor(i / b));
  }

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

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

int main() {
  ll A, B, N;
  cin >> A >> B >> N;
  ll x = min(N, B - 1);
  cout << (ll)(floor(A * x / B) - A * floor(x / B)) << endl;
}

Error: TLE

Fixed submission:

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

int main() {
  ll A, B, N;
  cin >> A >> B >> N;
  ll res = 0;
  for (ll x = N; x - B <= x && 0 <= x; x--) {
    res = max(res, (ll)(floor((A * x) / B) - A * floor(x / B)));
  }
  cout << res;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i, n, k) for (int i = (n); i < (k); i++)
#define ALL(a) (a).begin(), (a).end()
ll ans = 0;
ll calc(ll a, ll b, ll x) { return a * x / b - x / b * a; }
void Main() {
  ll a;
  cin >> a;
  ll b;
  cin >> b;
  ll n;
  cin >> n;
  for (ll i = min(b, n); i > 0; i--) {
    ll t = calc(a, b, i);
    if (t > ans)
      ans = t;
    else if (t < ans)
      break;
  }
  cout << ans << endl;
}
int main() {
  Main();
  /*
  東方風神録は神が出てくるので当然神ゲー
  */
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i, n, k) for (int i = (n); i < (k); i++)
#define ALL(a) (a).begin(), (a).end()
ll ans = 0;
ll calc(ll a, ll b, ll x) { return a * x / b - x / b * a; }
void Main() {
  ll a;
  cin >> a;
  ll b;
  cin >> b;
  ll n;
  cin >> n;
  for (ll i = 1; i < n + 1; i++) {
    ll t = calc(a, b, i);
    if (t > ans)
      ans = t;
    else if (t < ans)
      break;
  }
  cout << ans << endl;
}
int main() {
  Main();
  /*
  東方風神録は神が出てくるので当然神ゲー
  */
  return 0;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

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

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#include <iostream>
#include <math.h>
using namespace std;
long double a, b, n, mx;
long double temp1, temp2;
int main() {
  cin >> a >> b >> n;
  mx = 0;
  for (long long i = 0; i <= n; i++) {
    temp1 = (a * i) / b;
    temp2 = i / b;
    if (mx < floor(temp1) - a * floor(temp2)) {
      mx = floor(temp1) - a * floor(temp2);
    }
  }
  cout << mx << endl;
  return 0;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

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

long long a, b, n;

long long f(long long x) { return (a * x) / b - a * (x / b); }

int main() {
  cin >> a >> b >> n;
  long long lo = 0, hi = n, mid;

  long long ans = 0;

  while (lo <= hi) {
    mid = (lo + hi) / 2;
    if (f(mid) >= ans) {
      lo = mid + 1;
      ans = f(mid);
    } else {
      hi = mid - 1;
    }
  }
  cout << ans << endl;
}


Error: TLE

Fixed submission:

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

long long a, b, n;

long long f(long long x) { return (a * x) / b - a * (x / b); }

int main() {
  cin >> a >> b >> n;
  long long lo = 0, hi = n, mid;

  while (hi - lo > 3) {
    mid = (hi + lo) >> 1;
    if (f(mid) > f(mid + 1))
      hi = mid;
    else
      lo = mid;
  }

  long long int ans = 0;
  for (int i = lo; i <= hi; i++) {
    ans = max(ans, f(i));
  }

  cout << ans << endl;
}
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 pii = pair<int, int>;
using pil = pair<pii, int>;

int main() {
  ll a, b, n;
  cin >> a >> b >> n;
  ll s = b - 1;
  int ans;
  bool ok = true;
  while (ok) {
    if (s <= n) {
      int x = (a * s) / b;
      int y = (s / b);
      ans = x - a * y;
      ok = false;
    } else
      s--;
  }
  cout << ans << endl;
}

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 pii = pair<int, int>;
using pil = pair<pii, int>;

int main() {
  ll a, b, n;
  cin >> a >> b >> n;
  int ans = -2e9;
  int r = n - b;
  for (ll i = max(1, r); i <= n; i++) {
    int x = (a * i) / b;
    int y = (i / b);
    int m = x - a * y;
    ans = max(ans, m);
  }
  cout << ans << endl;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
typedef long long LL;
inline LL read() {
  LL kk = 0, f = 1;
  char cc = getchar();
  while (cc < '0' || cc > '9') {
    if (cc == '-')
      f = -1;
    cc = getchar();
  }
  while (cc >= '0' && cc <= '9') {
    kk = (kk << 1) + (kk << 3) + cc - '0';
    cc = getchar();
  }
  return kk * f;
}
LL a, b, n, x;
int main() {
  scanf("%lld%lld%lld", &a, &b, &n);
  x = min(n, b - 1);
  printf("%lld\\n", (a * x) / b);
}


Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
long long i, n, a, b, ans;
int main() {
  cin >> a >> b >> n;
  ans = a / b - a * (1 / b);
  for (i = 2; i <= n; i++) {
    if (ans < a * i / b - a * (i / b))
      ans = a * i / b - a * (i / b);
  }
  cout << ans << endl;
  ;
  return 0;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  ll a, b, n, tmp, tmp1, tmp2, ans;
  cin >> a >> b >> n;
  tmp = n / b * b - 1;
  tmp1 = floor(a * tmp / b) - a * floor(tmp / b);
  tmp2 = floor(a * n / b) - a * floor(n / b);
  ans = tmp1 >= tmp2 ? tmp1 : tmp2;
  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  ll a, b, n, tmp, ans;
  cin >> a >> b >> n;
  ans = 0;
  for (int i = 1; i <= n; i++) {
    tmp = floor(a * i / b) - a * floor(i / b);
    if (tmp > ans)
      ans = tmp;
  }
  cout << ans << endl;
  return 0;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

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

long long A, B, N, M;

long long F(long long X) { return floor((A * X) / B); }

int main() {

  cin >> A >> B >> N;

  M = min(B - 1, N);

  cout << F(M) << endl;
}


Error: TLE

Fixed submission:

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

#include <bits/stdc++.h>
using namespace std;
int main() {
  long long A, B, N, x;
  cin >> A >> B >> N;
  x = min(N, B - 1);
  cout << floor(A * x / B) - A * floor(x / B);
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#include <ctime>
#include <stdio.h>

using namespace std;
typedef string STR;
typedef long long LL;

// variables()
/*int N, min_r = 1000001, max_c = -1000001, mn = 1000001, mx = -1000001;
pair <int, int> pr;
vector <pair <int, int> > vc;*/
/// int plank, T, n, l, r, ans, sq, rct;
/// STR op;
/// vector <int> vc;
long A, B, N, mx = -1;
// variables(NULL)

int main() {
  ios_base::sync_with_stdio(NULL);
  cin.tie(0);
  cout.tie(0);
  srand(time(0));
  /// start_main()
  /*cin >> N;
  int grid[N][N];
  for (int i = 0 ; i < N ; i ++) {
  for (int j = 0 ; j < N ; j ++) {
      cin >> grid[i][j];
  }
  }
  for (int i = 0 ; i < N ; i ++) {
  for (int j = 0 ; j < N ; j ++) {
      min_r = min(min_r, grid[i][j]);
      max_c = max(max_c, grid[j][i]);
  }
  pr.first = min_r;
  pr.second = max_c;
  vc.push_back(pr);
  min_r = 1000001;
  max_c = -1000001;
  }
  for (int i = 0 ; i < N ; i ++) {
  mx = max(mx, vc[i].first);
  mn = min(mn, vc[i].second);
  }
  if (mx == mn) cout << 0;
  else {
  if (mx < mn) cout << 1;
  else cout << 2;
  multiset
  }
  cin >> plank;
  int arr[plank];
  for (int i = 0 ; i < plank ; i ++) {
  cin >> n;
  vc.push_back(n);
  }
  sort (vc.begin(), vc.end());
  r = vc.size() - 1;
  while (T --) {
  cin >> op >> n;
  if (op == '+') {
      vc.push_back(n);
      sort (vc.begin(), vc.end());
  }
  else {
      while (l <= r) {
          int m = l + (r - l) / 2;
          if (vc[m] == n) {
              ans = m;
              break;
          }
          if (vc[m] < n) l = m + 1;
          else r = m - 1;
      }
      vc.pop(m);
  }
  for (int i = 0 ; i < vc.size() ; i ++) {
      for (int j = i + 1 ; j < vc.size() ; j ++) {
          if (vc[i] == vc[j]) {

          }
      }
  }
  }*/
  cin >> A >> B >> N;
  for (int x = N / 2; x <= N; x++) {
    mx = max(mx, A * x / B - A * (x / B));
  }
  cout << mx;
  /// end_main()
  return 0;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cassert>
#include <cfenv>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <string>
#include <vector>

using namespace std;

int main() {
  double a, b, n;
  cin >> a >> b >> n;
  map<int, int> an;
  int count = 0;
  double i = 0;
  int tem = 0;
  int max = 0;
  int key = 0;
  double tem2;
  i = b - 1;
  tem = floor(a * i / b) - a * floor(i / b);
  i = n;
  tem2 = floor(a * i / b) - a * floor(i / b);
  if (b - 0.1 < n)
    cout << tem << endl;
  else
    cout << tem2 << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cassert>
#include <cfenv>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <string>
#include <vector>

using namespace std;

int main() {
  double a, b, n;
  cin >> a >> b >> n;
  int max = 0;
  int bx = b - 1;
  if (bx > n)
    bx = n;
  for (int i = bx; i <= n; i = i + b) {
    int tem = floor(a * i / b) - a * floor(i / b);
    if (max < tem)
      max = tem;
  }

  cout << max << endl;

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

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

int64_t sol(int64_t a, int64_t b, int64_t n) {
  int64_t i = min(n, b - 1);
  return floor((double)a * i / b) - a * floor((double)i / b);
}

int main() {
  int64_t a, b, n;
  cin >> a >> b >> n;
  cout << sol(a, b, n);
  return 0;
}

Error: TLE

Fixed submission:

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

int64_t sol(int64_t a, int64_t b, int64_t n) {
  int64_t before = -1, cur = 0, i = 1;
  for (i = 1; i <= min((int64_t)5e8, n); ++i) {
    cur = floor((double)a * i / b) - a * floor((double)i / b);
    if (before > cur) {
      break;
    }
    before = cur;
  }
  return before;
}

int main() {
  int64_t a, b, n;
  cin >> a >> b >> n;
  cout << sol(a, b, n);
  return 0;
}
Problem p02696 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int64_t a, b, n;
  cin >> a >> b >> n;
  int64_t ans1 = a * n / b - a * (n / b);
  int64_t ans2 = 0;
  if (b != 1) {
    if (n >= b - 1)
      ans2 = a * (b - 1) / b;
  }
  cout << max(ans1, ans2) << endl;
}

Error: 0

Fixed submission:

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

int main() {
  int64_t a, b, n;
  cin >> a >> b >> n;
  int64_t ans1 = a * n / b - a * (n / b);
  int64_t ans2 = 0;
  int x = b - 1;
  if (n >= b - 1)
    ans2 = a / (b - 1);
  cout << max(ans1, ans2) << endl;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

/**
 *    author: gxfireball
 **/
#include <bits/stdc++.h>
#define ll long long
#define endl '\\n'
#define fastio                                                                 \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
using namespace std;

void solve() {
  ll a, b, n, x;
  cin >> a >> b >> n;
  if (n >= b)
    x = b - 1;
  else
    x = n;
  cout << floor((a * x) / b) << endl;
}

int main() {
  fastio;
  int t;
  t = 1;
  // cin>>t;
  while (t--) {
    solve();
  }
  return 0;
}


Error: TLE

Fixed submission:

/**
 *    author: gxfireball
 **/
#include <bits/stdc++.h>
#define ll long long
#define endl '\\n'
#define fastio                                                                 \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
using namespace std;

void solve() {
  ll a, b, n;
  cin >> a >> b >> n;
  ll temp = min(n, b);
  ll ans = INT_MIN;
  for (ll i = 1; i <= temp; ++i) {
    ll k = floor((a * i) / b) - a * floor(i / b);
    ans = max(ans, k);
  }
  cout << ans << endl;
}

int main() {
  fastio;
  int t;
  t = 1;
  // cin>>t;
  while (t--) {
    solve();
  }
  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;

  long long int x = min(B - 1, N);

  long long int ans = A * x / B - x / B * A;

  cout << ans << endl;
}

Error: TLE

Fixed submission:

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

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

  long long int x = min(B - 1, N);

  long long int ans = 0;

  while (true) {
    long long int tmp_ans = A * x / B - x / B * A;
    if (tmp_ans > ans) {
      ans = tmp_ans;
    }
    if (x == N) {
      break;
    }
    x = min(x + B, N);
  }

  cout << ans << endl;
}