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)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
// const ll mod = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(25);

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

  cout << a * min(b - 1, n) / b << '\\n';

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
// const ll mod = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(25);

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

  ll ans = -INF;
  for (ll x = b - 1; x <= n; x += b) {
    ll res1 = a * x / b;
    ll res2 = x / b * a;
    chmax(ans, res1 - res2);
  }
  ll x = n;
  ll res1 = a * x / b;
  ll res2 = x / b * a;
  chmax(ans, res1 - res2);
  cout << ans << '\\n';

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

#include <cmath>
#include <cstdint>
#include <iostream>

using namespace std;

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

  int64_t minus = N % B;
  int64_t x = N - minus - 1;
  if (x < 0)
    x = N;
  int64_t res = floor(A * x / B) - A * floor(x / B);

  cout << res << endl;

  return 0;
}


Error: TLE

Fixed submission:

#include <cmath>
#include <cstdint>
#include <iostream>

using namespace std;

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

  int64_t res = -1;
  int64_t x = min(B - 1, N);
  while (x <= N) {
    int64_t tmp = floor(A * x / B) - A * floor(x / B);
    res = max(res, tmp);
    x += B;
  }
  cout << res << endl;

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

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

long long mmax(long long a, long long b) {
  if (a > b)
    return a;
  return b;
}

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

  if (b == 1) {
    cout << 0 << endl;
    return 0;
  }

  if (n < b)
    cout << a * n / b << endl;
  else {
    long long x, maxn = 0;
    for (x = b - 1ll; x <= n; x += b)
      maxn = mmax(maxn, a * x / b - a * (x / b));
    cout << maxn << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

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

long long mmax(long long a, long long b) {
  if (a > b)
    return a;
  return b;
}

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

  if (n < b)
    cout << a * n / b << endl;
  else {
    long long x, maxn = 0;
    for (x = b - 1ll; x <= n; x += b)
      maxn = mmax(maxn, a * x / b - a * (x / b));
    cout << maxn << endl;
  }
  return 0;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

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

// #pragma gcc optimize("O3,unroll-loop")
// #pragma gcc
// target("sse,sse2,sse3,ssse3,sse4,avx,avx2,fma,abm,mmx,popcnt,tune=native")
#define int long long
// #define double long double

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);

  int a, b, n;
  cin >> a >> b >> n;
  cout << a * min(n, (b - 1)) / b - a * (min(n, (b - 1)) / b) << '\\n';

  return 0;
}

//      *   *  *****  *   *  *   *
//     *   *  *      **  *  *   *
//    *****  *****  * * *  *   *
//   *   *      *  *  **  *   *
//  *   *  *****  *   *   ***

//      ***** ***** *   * *     ***** *   * ***** *****
//        *  *   * *   * *       *   **  *   *   *   *
//       *  *   * ***** *       *   * * *   *   *****
//   *  *  *   *   *   *       *   *  **   *   *
//  ****  *****   *   ***** ***** *   *   *   *


Error: TLE

Fixed submission:

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

// #pragma gcc optimize("O3,unroll-loop")
// #pragma gcc
// target("sse,sse2,sse3,ssse3,sse4,avx,avx2,fma,abm,mmx,popcnt,tune=native")
#define int long long
// #define double long double

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);

  int a, b, n, mx = 0;
  cin >> a >> b >> n;
  if (a == 1 || b == 1)
    cout << "0\\n", exit(0);
  for (int i = 0; i <= n; i++) {
    int now = a * i / b - a * (i / b);
    if (now < mx)
      cout << mx << '\\n', exit(0);
    mx = now;
  }
  cout << mx << '\\n';

  return 0;
}

//      *   *  *****  *   *  *   *
//     *   *  *      **  *  *   *
//    *****  *****  * * *  *   *
//   *   *      *  *  **  *   *
//  *   *  *****  *   *   ***

//      ***** ***** *   * *     ***** *   * ***** *****
//        *  *   * *   * *       *   **  *   *   *   *
//       *  *   * ***** *       *   * * *   *   *****
//   *  *  *   *   *   *       *   *  **   *   *
//  ****  *****   *   ***** ***** *   *   *   *
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define ll long long int
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll a, b, n;
  cin >> a >> b >> n;
  ll i;
  if (n <= b - 1) {
    cout << floor((a * n) / b) << endl;
  } else {
    cout << floor((a * (b - 1)) / b) << endl;
  }
  // cout<<max1<<endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define ll long long int
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll a, b, n;
  cin >> a >> b >> n;
  ll i;
  ll max1;
  ll a1;
  max1 = INT_MIN;
  for (i = 0; i <= n; i++) {
    a1 = floor((a * i) / b) - a * floor(i / b);
    max1 = max(max1, a1);
  }
  cout << max1 << endl;
  return 0;
}
Problem p02696 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define F first
#define S second

using namespace std;
typedef long long int64;

int64 a, b, n;

int64 f(int64 x) {
  int64 res = a * x / b - a * (x / b);
  return res;
}

int64 ternary_search(int64 l, int64 r) {
  while (r > l) {
    int64 m1 = l + (r - l) / 3;
    int64 m2 = r - (r - l) / 3;
    int64 f1 = f(m1);
    int64 f2 = f(m2);
    if (f1 <= f2)
      l = m2;
    else
      r = m1;
  }
  return max({f(l), f(min(l + 1, n)), f(max(1LL, l - 1))});
}

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

  cin >> a >> b >> n;
  cout << ternary_search(1, min(n, b));
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define F first
#define S second

using namespace std;
typedef long long int64;

int64 a, b, n;

int64 f(int64 x) { int64 res = a * x / b - a * (x / b); }

int64 ternary_search(int64 l, int64 r) {
  while (r > l) {
    int64 m1 = l + (r - l) / 3;
    int64 m2 = r - (r - l) / 3;
    int64 f1 = f(m1);
    int64 f2 = f(m2);
    if (f1 <= f2)
      l = m2;
    else
      r = m1;
  }
  return f(l);
}

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

  cin >> a >> b >> n;
  cout << ternary_search(1, n);
}
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 ans;
  if (b <= n)
    ans = a * (b - 1) / b;
  else
    ans = a * n / b;
  cout << ans << endl;
}


Error: TLE

Fixed submission:

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

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

#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
using namespace std;
int main() {
  ll a, b, n;
  cin >> a >> b >> n;
  ll max = 0, c, check;
  if (b > n) {
    check = n;
  } else {
    check = b - 1;
  }
  c = (a * check) / b - (check / b) * a;
  cout << c;
}

Error: TLE

Fixed submission:

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

#include <stdio.h>
long long n, m, i, j, k, a, b;
int main() {
  scanf("%lld%lld%lld", &a, &b, &n);
  if (n >= b)
    n = b - 1;
  printf("%lld\\n", a * n / b - a * (n / b));
  return 0;
}

Error: TLE

Fixed submission:

#include <stdio.h>
long long n, m, i, j, k, a, b;
int main() {
  scanf("%lld%lld%lld", &a, &b, &n);
  for (i = 0; i <= n; i++) {
    if (a * i / b - a * (i / b) > m) {
      m = a * i / b - a * (i / b);
      k = i;
    }
  }
  printf("%lld\\n", m);
  return 0;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

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

// GNU C Compiler
// template<class T> inline string toString(T x) { ostringstream sout; sout <<
// x; return sout.str(); }

// type
using ll = int_fast64_t;
using ull = uint_fast64_t;
using LL = long long;
using ULL = unsigned long long;
using PII = pair<int, int>;
// using pair<T1, T2> = p12;

// container
#define PB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define ALL(v) v.begin(), v.end()

// repetition
#define REP(n) for (int i = 0; i < (n); i++)
#define REPj(n) for (int j = 0; j < (n); j++)
#define REPinit(i, a, n) for (int i = (a); i < (n); i++)
#define REPinitj(j, a, n) for (int j = (a); j < (n); j++)

// algorithm
// #define SORT(c) sort((c).begin(),(c).end())

// constant

// clear memory
#define CLR(a) memset((a), 0, sizeof(a))

// Optimizer
//  #pragma GCC optimize("Ofast")
//  #pragma GCC
//  target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

/*
    add utility Algorithm
*/

int main(int argc, char const *argv[]) {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

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

  if (N < B) {
    cout << ll((A * N) / B) << endl;
  } else {

    ll ans = (A * (B - 1) / B);
    ll tmp;

    ll left = B - 1;
    // ll right = N / B;
    ll right = N;

    while ((right - left) > 1) {
      ll mid = (left + right) / 2;
      // tmp = (A * (mid + B - 1) / B) - A * mid;
      tmp = (A * (mid) / B) - A * (mid / B);
      if (ans < tmp) {
        ans = tmp;
        left = mid;
      } else {
        right = mid;
      }
    }
    cout << ans << endl;
  }

  return 0;
}


Error: TLE

Fixed submission:

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

// GNU C Compiler
// template<class T> inline string toString(T x) { ostringstream sout; sout <<
// x; return sout.str(); }

// type
using ll = int_fast64_t;
using ull = uint_fast64_t;
using LL = long long;
using ULL = unsigned long long;
using PII = pair<int, int>;
// using pair<T1, T2> = p12;

// container
#define PB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define ALL(v) v.begin(), v.end()

// repetition
#define REP(n) for (int i = 0; i < (n); i++)
#define REPj(n) for (int j = 0; j < (n); j++)
#define REPinit(i, a, n) for (int i = (a); i < (n); i++)
#define REPinitj(j, a, n) for (int j = (a); j < (n); j++)

// algorithm
// #define SORT(c) sort((c).begin(),(c).end())

// constant

// clear memory
#define CLR(a) memset((a), 0, sizeof(a))

// Optimizer
//  #pragma GCC optimize("Ofast")
//  #pragma GCC
//  target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

/*
    add utility Algorithm
*/

int main(int argc, char const *argv[]) {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

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

  if (N < B) {
    cout << ll((A * N) / B) << endl;
  } else {
    ll left = 0;
    ll right = N / B;
    ll tmp = 0;
    ll ans = -1;

    for (int i = 0; i < N; i += right) {
      tmp = (A * (i + B - 1) / B) - A * i;
      if (ans < tmp) {
        ans = tmp;
      }
    }

    cout << ans << endl;
  }

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

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <string>
#include <vector>
#define rip(i, n) for (int i = 0; i < n; i++)
#define ll long long
#define ld long double
#define set setprecision　 //小数点以下何位まで知りたいか
#define mod 1000000007
#define pi 3.14159265
#include <numeric>
using namespace std;
int gcd(int a, int b) // 最大公約数
{
  if (a % b == 0)
    return (b);
  else
    return (gcd(b, a % b));
}
int lcm(int a, int b) // 最小公倍数
{
  return a * b / gcd(a, b);
}
ll pow(ll a, ll b) {
  ll k = b % 30000, h = b / 30000, s = 1;
  rip(i, 30000) s = (s * a) % mod;
  ll j = 1;
  if (h != 0)
    rip(i, h) j = j * s % mod;
  if (k != 0)
    rip(i, k) j = j * a % mod;
  ;
  return (j);
}
int main() {
  ll a, b, n;
  cin >> a >> b >> n;
  if (n / b > 100000000) {
    ll p = n / b;
    cout << ((floor(a * n / b)) - a * (floor(n / b))) << endl;
  } else {
    ll k = n / b;
    ll s;
    ll maxx = 0;
    for (int i = 0; i <= k; i++) {
      s = (i + 1) * b - 1;
      if (i == k)
        s = n;
      if (maxx < ((floor(a * s / b)) - a * (floor(s / b)))) {
        maxx = ((floor(a * s / b)) - a * (floor(s / b)));
      }
    }
    cout << maxx << endl;
  }
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <string>
#include <vector>
#define rip(i, n) for (int i = 0; i < n; i++)
#define ll long long
#define ld long double
#define set setprecision　 //小数点以下何位まで知りたいか
#define mod 1000000007
#define pi 3.14159265
#include <numeric>
using namespace std;
int gcd(int a, int b) // 最大公約数
{
  if (a % b == 0)
    return (b);
  else
    return (gcd(b, a % b));
}
int lcm(int a, int b) // 最小公倍数
{
  return a * b / gcd(a, b);
}
ll pow(ll a, ll b) {
  ll k = b % 30000, h = b / 30000, s = 1;
  rip(i, 30000) s = (s * a) % mod;
  ll j = 1;
  if (h != 0)
    rip(i, h) j = j * s % mod;
  if (k != 0)
    rip(i, k) j = j * a % mod;
  ;
  return (j);
}
int main() {
  ll a, b, n;
  cin >> a >> b >> n;
  ll k = n / b;
  ll s;
  ll maxx = 0;
  for (int i = 0; i <= k; i++) {
    s = (i + 1) * b - 1;
    if (i == k)
      s = n;
    if (maxx < ((floor(a * s / b)) - a * (floor(s / b)))) {
      maxx = ((floor(a * s / b)) - a * (floor(s / b)));
    }
  }
  cout << maxx << endl;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cstdio>
#include <iostream>
#define ll long long
using namespace std;

int main()

{
  ll a, b, n;
  cin >> a >> b >> n;
  if (b == 1) {
    cout << 0 << endl;
    return 0;
  }
  ll ans = -1e18;

  n = min(n, b - 1);

  ans = max(ans, (a * n) / b - a * (n / b));

  cout << ans << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <iostream>
#define ll long long
using namespace std;

int main()

{
  ll a, b, n;
  cin >> a >> b >> n;
  if (b == 1) {
    cout << 0 << endl;
    return 0;
  }
  ll ans = -1e18;

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

#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
#define int long long
using namespace std;

int a, b, n;
int ans = 0;

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

void solve(int l, int r) {
  if (l > r)
    return;
  int mid = (l + r) >> 1;
  int tmp = calc(mid);
  if (!mid)
    solve(l, mid);
  else {
    ans = tmp;
    solve(mid + 1, r);
  }
}

signed main() {
  cin >> a >> b >> n;
  int x = min(b, n);
  int t = x;
  int sq = sqrt(x);
  while (x >= 0 && !calc(x))
    x -= sq;
  while (1) {
    if (x >= t) {
      cout << calc(t);
      return 0;
    }
    if (!calc(x + 1)) {
      cout << calc(x);
      return 0;
    }
    ++x;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <vector>
#define int long long
using namespace std;

int a, b, n;
int ans = 0;

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

signed main() {
  cin >> a >> b >> n;
  int ans = min(b, n);
  while (!calc(ans))
    --ans;
  cout << calc(ans);
  // if(a % b == 0) cout << calc(min(b - 1, n));
  // else if(b % a == 0) cout << calc(min(b - 1, n));
  // else cout << calc(n);
  return 0;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>

// using namespace std;
using std::cin, std::cout, std::endl, std::string;
using ll = long long;

#define rep(countName, left, right, up)                                        \\
  for (auto countName = left; countName < right; countName += up)
#define REP(countName, end)                                                    \\
  for (auto countName = 0; countName < end; countName++)
#define rev(countName, right, left, down)                                      \\
  for (auto countName = right; countName >= left; countName -= down)
#define REV(countName, end)                                                    \\
  for (auto countName = end; countName >= 0; countName--)

auto solve1(ll a, ll b, ll n) {
  auto min = std::min(b - 1, n);
  return ((a * min) / b) - a * (min / b);
}

int main(void) {
  ll a, b, n;
  cin >> a >> b >> n;
  cout << solve1(a, b, n) << endl;

  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>

// using namespace std;
using std::cin, std::cout, std::endl, std::string;
using ll = long long;

#define rep(countName, left, right, up)                                        \\
  for (auto countName = left; countName < right; countName += up)
#define REP(countName, end)                                                    \\
  for (auto countName = 0; countName < end; countName++)
#define rev(countName, right, left, down)                                      \\
  for (auto countName = right; countName >= left; countName -= down)
#define REV(countName, end)                                                    \\
  for (auto countName = end; countName >= 0; countName--)

auto solve1(ll a, ll b, ll n) {
  ll ans = 0;
  rep(x, 0, n + 1, b - 1) { ans = std::max(ans, ((a * x) / b) - a * (x / b)); }
  ans = std::max(ans, ((a * n) / b) - a * (n / b));
  return ans;
}

int main(void) {
  ll a, b, n;
  cin >> a >> b >> n;
  cout << solve1(a, b, n) << endl;

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

/**
 *    created: 22.05.2020 23:39:24
 **/
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using namespace std;

signed main() {

  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int a, b, n;
  cin >> a >> b >> n;
  int t = min(n, b - 1);
  cout << floor(a * t / b) << endl;
  return 0;
}

Error: TLE

Fixed submission:

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

int a, b, n;
int flr(int k) {
  int ans = floor(a * k / b) - a * floor(k / b);
  return ans;
}
signed main() {

  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  cin >> a >> b >> n;
  int ans = -50000;
  rep(i, n + 1) { ans = max(ans, flr(i)); }
  cout << ans << endl;
  return 0;
}
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<ll, ll>;
const int mod = 1e9 + 7;
// const int mod = 998244353;
const ll infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;
void YesNo(bool j) {
  cout << (j ? "Yes" : "No") << endl;
  return;
}
void yesno(bool j) {
  cout << (j ? "yes" : "no") << endl;
  return;
}
template <class Head> void pt(Head &&head) {
  cout << head << endl;
  return;
}

int main() {
  ll a, b, n;
  cin >> a >> b >> n;
  ll c = 0, ans = 0;
  ll d = n / b * b - 1;
  if (n - d == b)
    d = n;
  if (n / b == 0) {
    ans = a * n / b - a * (n / b);
  } else {
    ans = a * d / b - a * (d / b);
  }

  pt(ans);
  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<ll, ll>;
const int mod = 1e9 + 7;
// const int mod = 998244353;
const ll infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;
void YesNo(bool j) {
  cout << (j ? "Yes" : "No") << endl;
  return;
}
void yesno(bool j) {
  cout << (j ? "yes" : "no") << endl;
  return;
}
template <class Head> void pt(Head &&head) {
  cout << head << endl;
  return;
}

int main() {
  ll a, b, n;
  cin >> a >> b >> n;
  ll c = 0, ans = 0;
  rep(i, n + 1) {
    c = a * i / b - a * (i / b);
    ans = max(ans, c);
    if (c == b - 1)
      break;
  }
  pt(ans);
  return 0;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int floor(long A, long B) { return A / B; }

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

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int floor(long A, long B) { return A / B; }

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

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

// f(x) = floor(Ax/B) - A floor(x/B)
// = Ax/B - (Ax % B) / B - A (x/B - (x%B)/B) ※ floor(X/Y) = (X-X%Y)/Y = X/Y -
// (X%Y)/Y を使いました。 = -(Ax%B)/B + A(x％B)/B ※ ここで、y＝x%B
// とおくと、y<=min(N,B-1) = -((Ay)％B)/B + (Ay)/B ※ Ax%B = A(x%B)%B
// を使いました。 = floor(Ay/B) ※ floorの式変形を逆に使いました。

int main(void) {
  long long A, B, N;
  cin >> A >> B >> N;
  long long y = min(N, B - 1);
  cout << static_cast<long long>(A * min(N, B - 1) / B) << endl;
  return 0;
}

Error: TLE

Fixed submission:

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

// f(x) = floor(Ax/B) - A floor(x/B)
// = Ax/B - (Ax % B) / B - A (x/B - (x%B)/B) ※ floor(X/Y) = (X-X%Y)/Y = X/Y -
// (X%Y)/Y を使いました。 = -(Ax%B)/B + A(x％B)/B ※ ここで、y＝x%B
// とおくと、y<=min(N,B-1) = -((Ay)％B)/B + (Ay)/B ※ Ax%B = A(x%B)%B
// を使いました。 = floor(Ay/B) ※ floorの式変形を逆に使いました。

int main(void) {
  long long A, B, N;
  cin >> A >> B >> N;
  long long result = 0;
  long long max = 0;
  long long y = min(N, B - 1);
  for (long long i = 1; i <= y; i++) {
    result = static_cast<long long>((A * (i % B)) / B);
    if (max < result)
      max = result;
  }
  cout << max << endl;
  return 0;
}