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

#include <bits/stdc++.h> //Carefully Crafted by hetp111
using namespace std;
#define int long long
#define double long double
#define all(v) (v).begin(), (v).end()
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define vii vector<pii>
#define MOD (1000000007)
#define MOD2 (998244353)
#define MOD3 (1000000009)
#define PI acos(-1)
#define eps (1e-8)
#define INF (1e18)
#define FASTER                                                                 \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0)
template <class A, class B>
ostream &operator<<(ostream &out, const pair<A, B> &a) {
  return out << "(" << a.first << "," << a.second << ")";
}
template <class A> ostream &operator<<(ostream &out, const vector<A> &a) {
  for (const A &it : a)
    out << it << " ";
  return out;
}
template <class A, class B> istream &operator>>(istream &in, pair<A, B> &a) {
  return in >> a.first >> a.second;
}
template <class A> istream &operator>>(istream &in, vector<A> &a) {
  for (A &i : a)
    in >> i;
  return in;
}
ifstream cinn("input.txt");
ofstream coutt("output.txt");

int a, b, n;

int ff(int x) { return (a * x) / b - a * (x / b); }

int f(int l, int r) {
  if (l > r)
    return 0;
  if (l / b == r / b) {
    return ff(r);
  }
  int mid = (l + r) / 2;
  return max(f(l, mid), f(mid + 1, r));
}

signed main() {
  FASTER;
  cin >> a >> b >> n;
  n = min(b, n);
  cout << f(0, n);
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h> //Carefully Crafted by hetp111
using namespace std;
#define int long long
#define double long double
#define all(v) (v).begin(), (v).end()
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define vii vector<pii>
#define MOD (1000000007)
#define MOD2 (998244353)
#define MOD3 (1000000009)
#define PI acos(-1)
#define eps (1e-8)
#define INF (1e18)
#define FASTER                                                                 \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0)
template <class A, class B>
ostream &operator<<(ostream &out, const pair<A, B> &a) {
  return out << "(" << a.first << "," << a.second << ")";
}
template <class A> ostream &operator<<(ostream &out, const vector<A> &a) {
  for (const A &it : a)
    out << it << " ";
  return out;
}
template <class A, class B> istream &operator>>(istream &in, pair<A, B> &a) {
  return in >> a.first >> a.second;
}
template <class A> istream &operator>>(istream &in, vector<A> &a) {
  for (A &i : a)
    in >> i;
  return in;
}
ifstream cinn("input.txt");
ofstream coutt("output.txt");

int a, b, n;

int ff(int x) { return (a * x) / b - a * (x / b); }

int f(int l, int r) {
  if (l > r)
    return 0;
  if (l / b == r / b) {
    return ff(r);
  }
  int mid = (l + r) / 2;
  return max(f(l, mid), f(mid + 1, r));
}

signed main() {
  FASTER;
  cin >> a >> b >> n;
  cout << f(0, n);
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#pragma GCC optimize("O3")
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

template <class T> inline T chmax(T &a, const T b) {
  return a = (a < b) ? b : a;
}
template <class T> inline T chmin(T &a, const T b) {
  return a = (a > b) ? b : a;
}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;

#define all(a) (a).begin(), (a).end()

int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};

ll a, b;

ll solve(ll x) { return (a * x / b) - a * (x / b); }

ll ternary_search(ll l, ll r) {
  ll left = l, right = r;

  // calculate maximum value
  for (int i = 0; i < 100; i++) {
    if (solve((left * 2 + right) / 3) > solve((left + right * 2) / 3)) {
      right = (left + right * 2) / 3;
    } else {
      left = (left * 2 + right) / 3;
    }
  }

  return solve((left + right) * 0.5);
}

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

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

  cout << ternary_search(0, n + 1) << endl;

  return 0;
}

Error: TLE

Fixed submission:

#pragma GCC optimize("O3")
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

template <class T> inline T chmax(T &a, const T b) {
  return a = (a < b) ? b : a;
}
template <class T> inline T chmin(T &a, const T b) {
  return a = (a > b) ? b : a;
}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;

#define all(a) (a).begin(), (a).end()

int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};

ll a, b;

ll solve(ll x) { return (a * x / b) - a * (x / b); }

ll ternary_search(ll l, ll r) {
  ll left = l, right = r;

  // calculate maximum value
  for (int i = 0; i < 100; i++) {
    if (solve((left * 2 + right) / 3) > solve((left + right * 2) / 3)) {
      right = (left + right * 2) / 3;
    } else {
      left = (left * 2 + right) / 3;
    }
  }

  ll ans = -INF;
  for (int i = left; i <= right; i++) {
    chmax(ans, solve(i));
  }

  return ans;
}

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

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

  cout << ternary_search(1, n) << endl;

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

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define PI 3.1415926535
#define MOD 1000000007

int main() {

  ll A, B, N;
  cin >> A >> B >> N;

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

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define PI 3.1415926535
#define MOD 1000000007

int main() {

  ll A, B, N;
  cin >> A >> B >> N;

  ll mx = 0;
  ll ans;
  for (ll i = 1; i <= min(N, B); i++) {
    ans = (ll)((i % B) * A / B);
    mx = max(mx, ans);
    // if(ans < 0)  cout << i; break;
  }

  cout << mx << endl;

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

/**
 *  Author : Parth Prajapati aka (PARTH_4399, hungry_chef)
 *  Institute : Pandit Deendayal Petroleum University
 **/
#include <bits/stdc++.h>

using namespace std;

#define start_cooking int main()
#define food_is_ready return 0;
#define main_ingredient_added                                                  \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);

start_cooking {
  main_ingredient_added
      // start with your recipe
      long long a,
      b, n;
  cin >> a >> b >> n;
  long long k;
  k = min(n, b - 1);
  cout << (a * k) / b - a * (k / b);
  food_is_ready
}

Error: TLE

Fixed submission:

/**
 *  Author : Parth Prajapati aka (PARTH_4399, hungry_chef)
 *  Institute : Pandit Deendayal Petroleum University
 **/
#include <bits/stdc++.h>

using namespace std;

#define start_cooking int main()
#define food_is_ready return 0;
#define main_ingredient_added                                                  \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);

start_cooking {
  main_ingredient_added
      // start with your recipe
      long long a,
      b, n;
  cin >> a >> b >> n;
  long long i, ans = 0;
  for (i = b - 1; i < n + 1; i += b)
    ans = max(ans, (a * i) / b - a * (i / b));
  i = n;
  ans = max(ans, (a * i) / b - a * (i / b));
  cout << ans;
  food_is_ready
}
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_i = min(b - 1, n);
  long long result = ((a * x_i) / b) - (a * (x_i / b));
  cout << result << endl;
  return 0;
}

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 s = b / a, ans = 0;
  for (ll i = s; i <= min(n, s + b + 1); i++) {
    ll pos = floor(a * i / b) - a * floor(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 int a, b, n;
  cin >> a >> b >> n;
  long long int val = min(b - 1, n);
  long long int ans = floor(a * val / b);
  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  long long int a, b, n;
  long long int ans = 0;
  cin >> a >> b >> n;
  if (a > b) {
    for (int i = 1; i <= n; i++) {
      long long int tmp = floor(a * i / b) - a * floor(i / b);
      ans = max(tmp, ans);
    }
  } else {
    for (int i = b / a; i <= n; i++) {
      long long int tmp = floor(a * i / b) - a * floor(i / b);
      ans = max(tmp, ans);
    }
  }
  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, M, x, maxim = -1;
int main() {
  cin >> A >> B >> M;
  if (M < B) {
    x = M;
    cout << A * x / B << '\\n';
  } else {
    x = B - 1;
    maxim = max(A * x / B - A * (x / B), maxim);
    long long coe = ((M + 1) / B) - 1;
    x = coe * B - 1;
    maxim = max(A * x / B - A * (x / B), maxim);
    x = M;
    maxim = max(A * x / B - A * (x / B), maxim);
    cout << maxim << '\\n';
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
long long A, B, M, x, maxim = -1;
int main() {
  cin >> A >> B >> M;
  if (M < B) {
    x = M;
    cout << A * x / B << '\\n';
  } else {
    x = B - 1;
    while (x < M) {
      maxim = max(A * x / B - A * (x / B), maxim);
      x += B;
    }
    x = M;
    maxim = max(A * x / B - A * (x / B), maxim);
    cout << maxim << '\\n';
  }
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  ll N, A, B;
  cin >> A >> B >> N;
  ll ans = 0;
  ll x;
  if (N < B) {
    x = N;
  } else {
    x = B - 1;
  }
  while (1) {
    ans = max(ans, ll(floor(A * x / B) - A * floor(x / B)));
    if (floor(A * x / B) != floor(A * (x - 1) / B)) {
      break;
    }
    x--;
  }
  cout << ans << endl;
}

Error: TLE

Fixed submission:

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

int main() {
  ll N, A, B;
  cin >> A >> B >> N;
  ll ans = 0;

  for (int x = 0; x < 1e9; x += 1) {
    ans = max(ans, ll(floor(A * x / B) - A * floor(x / B)));
  }
  cout << ans << endl;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

#define whole(f, x, ...)                                                       \\
  ([&](decltype((x)) whole) {                                                  \\
    return (f)(begin(whole), end(whole), ##__VA_ARGS__);                       \\
  })(x)

using namespace std;
using ll = long long;

void solve() {
  ll a, b, n;
  cin >> a >> b >> n;

  const ll x = min(b - 1, n);

  const ll ans = (floor(a * x / b) - a * floor(x / b));

  std::cout << ans << endl;
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);

  solve();
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

#define whole(f, x, ...)                                                       \\
  ([&](decltype((x)) whole) {                                                  \\
    return (f)(begin(whole), end(whole), ##__VA_ARGS__);                       \\
  })(x)

using namespace std;
using ll = long long;

void solve() {
  ll a, b, n;
  cin >> a >> b >> n;

  ll ma = 0;

  for (ll i = 2 * n / 3; i <= n; i++) {
    ma = max(ma, (ll)(floor(a * i / b) - a * floor(i / b)));
  }
  cout << ma << endl;
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);

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

#include <iostream>
using namespace std;

int main() {
  long long A, B, N, i, max;
  cin >> A >> B >> N;
  i = N;
  if (N >= B - 1)
    i = B - 1;
  max = ((A * i) / B) - (A * (i / B));
  cout << max << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

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

#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 2e5 + 5, mod = 1e9 + 7;

ll a, b, n;

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

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> a >> b >> n;
  ll low = 1, high = n, mid1, mid2;
  int cnt = 0;
  while (high - low > 3) {
    mid1 = low + (high - low) / 3;
    mid2 = high - (high - low) / 3;
    if (f(mid1) > f(mid2)) {
      high = mid2;
    } else
      low = mid1;
  }
  ll ans = 0;
  for (ll i = low; i <= high; i++)
    ans = max(ans, f(i));
  cout << ans;

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 2e5 + 5, mod = 1e9 + 7;

ll a, b, n;

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

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> a >> b >> n;
  ll low = 1, high = n, mid1, mid2;
  while (high - low > 3) {
    mid1 = low + (high - low) / 3;
    mid2 = high - (high - low) / 3;
    if (f(mid1) > f(mid2)) {
      high = mid2;
    } else
      low = mid1;
  }
  ll ans = 0;
  for (int i = low; i <= high; i++)
    ans = max(ans, f(i));
  cout << ans;

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

#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
int main() {
  long long a, b, x;
  cin >> a >> b >> x;
  long long n = min(b - 1, x);
  cout << (a * n) / b - a * (n / b) << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
int main() {
  long long a, b, n;
  long long ma = 0;
  cin >> a >> b >> n;
  for (long long j = n; j >= n - 100000000; j--) {
    if (j < 0) {
      break;
    }
    if (ma < (a * j) / b - a * (j / b)) {
      ma = (a * j) / b - a * (j / b);
    }
  }
  for (long long j = 0; j < 100000000; j++) {
    if (j > n) {
      break;
    }
    if (ma < (a * j) / b - a * (j / b)) {
      ma = (a * j) / b - a * (j / b);
    }
  }
  if (ma < (a * (n / 2)) / b - a * ((n / 2) / b)) {
    ma = (a * (n / 2)) / b - a * ((n / 2) / b);
  }
  cout << ma << endl;
  return 0;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  ll a, b, N;
  ll x, y, z, zz;
  cin >> a >> b >> N;
  // for (x = 1; x < n + 1;x++){
  //   y = x / b;
  // z = a * x / b - a * y;
  /*  if(x==1){
      zz = z;
      xx = x;
  }
  if(z>zz){
      zz = z;
      xx = x;
  }*/
  // cout << z << endl;
  /*
  if (b == 1||a==1)
  {
      cout << 0 << endl;
      break;
 }
 if(x==b-1){
     cout << z << endl;
     break;
 }*/
  /* if(z==0){
       y = (x - 1) / b;
       cout << a * (x - 1) / b - a * y << endl;
       break;
   }*/
  //}
  y = N / b;
  ll y2 = (b - 1) / b;

  // N > b - 1 && a * N / b - a * y != 0

  if (b == 1 || a == 1) {
    cout << 0 << endl;
  } else if (N <= b - 1) {
    cout << a * N / b - a * y << endl;
  } else if (N > b - 1) {
    cout << a * (b - 1) / b - a * y2 << endl;
  }

  // cout << zz << endl;
}

Error: TLE

Fixed submission:

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

int main() {
  ll a, b, n;
  ll x, y, z, zz;
  cin >> a >> b >> n;
  for (x = 1; x < n + 1; x++) {
    y = x / b;
    z = a * x / b - a * y;

    if (b == 1 || a == 1) {
      cout << 0 << endl;
      break;
    }
    if (x == b - 1) {
      cout << z << endl;
      break;
    }
  }

  if (x == n + 1 && z != 0) {
    cout << z << endl;
  }
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
typedef long long ll;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Rep(i, k, n) for (int i = k; i < (int)(n); i++)

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


Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
typedef long long ll;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Rep(i, k, n) for (int i = k; i < (int)(n); i++)

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

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

long A, B, N;

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

int main() {
  cin >> A >> B >> N;
  long min = N > B - 1 ? B - 1 : N;
  cout << f(min) << endl;
  return 0;
}

Error: TLE

Fixed submission:

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

long A, B, N;

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

int main() {
  cin >> A >> B >> N;
  long cnt = N > B ? B : N;
  long max = -100;
  for (long x = 1; x <= cnt; x++) {
    long now = f((double)x);
    max = max > now ? max : now;
  }
  cout << max << endl;
  return 0;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <climits>
#include <cmath>
#include <iostream>
typedef long long ll;
using namespace std;
int main() {
  ll a;
  cin >> a;
  ll b;
  cin >> b;
  ll n;
  cin >> n;
  ll k = min(b - 1, n);
  ll medi = floor((a * k) / b) - a * (floor(k / b));

  cout << medi;
}


Error: TLE

Fixed submission:

#include <climits>
#include <cmath>
#include <iostream>
typedef long long ll;
using namespace std;
int main() {
  ll a;
  cin >> a;
  ll b;
  cin >> b;
  ll n;
  cin >> n;
  ll k = min(b, n);
  ll answer = INT_MIN;
  for (ll i = k; a * i >= b; i--) {
    ll medi = floor((a * i) / b) - a * (floor(i / b));
    answer = max(answer, medi);
  }
  cout << answer;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i, s, n) for (int i = s; i < n; i++)
#define rep(i, n) reps(i, 0, n)
#define Rreps(i, n, e) for (int i = n - 1; i >= e; --i)
#define Rrep(i, n) Rreps(i, n, 0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N, M, H, W, Q, K, A, B;
string S;
const ll MOD = 998244353;
// const ll MOD = (1e+9) + 7;
typedef pair<ll, ll> P;
const ll INF = (1LL << 50);
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  } else
    return false;
}
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  } else
    return false;
}

int main() {
  cin >> A >> B >> N;
  ll x = min(N, B - 1);
  if (x == N) {
    cout << (A * x) / B - A * (x / B) << endl;
    return 0;
  }
  ll ans = (A * x) / B - A * (x / B);
  x += B;
  while (x <= N && (A * x) % B != (A * (B - 1)) % B) {
    chmax(ans, (A * x) / B - A * (x / B));
    x += B;
  }
  cout << ans << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i, s, n) for (int i = s; i < n; i++)
#define rep(i, n) reps(i, 0, n)
#define Rreps(i, n, e) for (int i = n - 1; i >= e; --i)
#define Rrep(i, n) Rreps(i, n, 0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N, M, H, W, Q, K, A, B;
string S;
const ll MOD = 998244353;
// const ll MOD = (1e+9) + 7;
typedef pair<ll, ll> P;
const ll INF = (1LL << 50);
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  } else
    return false;
}
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  } else
    return false;
}

int main() {
  cin >> A >> B >> N;
  ll x = min(N, B - 1);
  if (x == N) {
    cout << (A * x) / B - A * (x / B) << endl;
    return 0;
  }
  ll ans = (A * x) / B - A * (x / B);
  while (x <= N && (A * x) % B == (A * (B - 1)) % B) {
    chmax(ans, (A * x) / B - A * (x / B));
    x += B;
  }
  cout << ans << endl;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
using namespace std;
const int MOD = 1000000007;
const ll INF = 1LL << 60;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll a, b, n;
  cin >> a >> b >> n;
  ll flag = min(b - 1, n);
  ll i = flag;
  ll num = (a * i) / b - a * (i / b);
  cout << num << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
using namespace std;
const int MOD = 1000000007;
const ll INF = 1LL << 60;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll a, b, n;
  cin >> a >> b >> n;
  ll m = -1;
  for (int i = 1; i <= n; i++) {
    if (i > b) {
      cout << m << endl;
      return 0;
    }
    ll num = (a * i) / b - a * (i / b);
    m = max(m, num);
  }
  cout << m << endl;
}