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 RREP(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
typedef long long ll;
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
// const ll INF = 1LL << 60;
// const int INF = 1001001001;

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

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define RREP(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
typedef long long ll;
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
// const ll INF = 1LL << 60;
// const int INF = 1001001001;

int main(void) {
  long a, b, n;
  cin >> a >> b >> n;
  long ans = 0;
  for (long i = 0; i <= n; i++) {
    long x = (a * i) / b, y = i / b;
    chmax(ans, x - a * y);
  }

  cout << ans;
  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 ans;
int main() {
  cin >> a >> b >> n;
  if (n < b) {
    cout << max(ans, a * n / b - a * (n / b));
  } else {
    if (a * b > n) {
      for (long long i = b - 1; i <= n; i += b) {
        long long tot = a * i / b - a * (i / b);
        if (tot > ans) {
          ans = tot;
        }
      }
    } else {
      for (long long i = 1; i <= a; i++) {
        long long tot = a * (i * b - 1) / b - a * (i - 1);
        if (tot > ans) {
          ans = tot;
        }
      }
    }
    cout << ans;
  }
  return 0;
}


Error: TLE

Fixed submission:

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

#include "bits/stdc++.h"

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using pi = pair<int, int>;
const ll INF = 1LL << 60;

int main() {
  ll a, b, n;
  cin >> a >> b >> n;
  ll x = min(b - 1, n);
  cout << a * (x % b) / b << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include "bits/stdc++.h"

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
using ll = long long;

template <typename T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b; // aをbで更新
    return true;
  }
  return false;
}

template <typename T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b; // aをbで更新
    return true;
  }
  return false;
}

using namespace std;
int main() {
  ll mmax = -1;
  ll A, B, N;
  cin >> A >> B >> N;
  vector<ll> c;
  for (int i = 1; i <= N; i++) {
    c.push_back((floor((A * i) / B) - A * floor(i / B)));
    mmax = max(mmax, c[i - 1]);
  }
  cout << mmax << endl;
  return 0;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <stdio.h>
#include <string>
#include <unordered_map>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
#define repn(i, n) for (int i = 1; i <= n; i++)
using namespace std;
typedef long long ll;

ll A, B, N;

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

  ll ans = A * min(N, B - 1) / B;

  cout << ans << endl;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <stdio.h>
#include <string>
#include <unordered_map>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
#define repn(i, n) for (int i = 1; i <= n; i++)
using namespace std;
typedef long long ll;

ll A, B, N;

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

  ll ans = 0;
  rep(i, max(N + 1, (ll)1000000)) {
    ans = max(ans, (A * (N - i)) / B - A * ((N - i) / B));
  }

  cout << ans << endl;
}
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 = min(b - 1, n);
  long long ans = 0;
  long long i = 1;

  long long tmp = floor(a * x / b) - a * floor(x / b);
  ans = max(ans, tmp);
  i++;
  x = b * i - 1;

  cout << ans << 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 = min(b - 1, n);
  long long ans = 0;
  long long i = 1;
  do {

    long long tmp = floor(a * x / b) - a * floor(x / b);
    ans = max(ans, tmp);
    i++;
    x = b * i - 1;
  } while (x <= n);
  cout << ans << endl;
  return 0;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

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

#define INF 100000000

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

  ll 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 <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)

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

  ll ans = 0;
  rep2(i, n - 1, n + 1) {
    ll temp = 0;
    temp = floor(a * i / b) - a * floor(i / b);
    ans = max(ans, temp);
  }

  cout << ans << endl;

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

#include <iostream>
using namespace std;

typedef long long ll;

int main() {
  ll a, b, n;
  cin >> a >> b >> n;
  ll ret = 0;
  for (ll x = min(b - 1, n); x <= n; x += b) {
    ret = max(ret, a * x / b - x / b * a);
    break;
  }
  ll tmp = n / b * b;
  tmp += b - 1;
  while (tmp > n)
    tmp -= b;
  ret = max(ret, a * tmp / b - tmp / b * a);
  cout << ret << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

typedef long long ll;

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

#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18;
typedef long long ll;
typedef vector<ll> vl;
#define rp(i, f, t) for (long long int i = f; i < t; i++)
#define pr(i, f, t) for (long long int i = t - 1; i >= f; i--)
#define ca(n, a)                                                               \\
  rp(ca_i, 0, n) cout << a[ca_i] << ((ca_i == n - 1) ? "\\n" : " ")
#define za(n, a) rp(za_i, 0, n) a[za_i] = 0
#define be(a) a.begin(), a.end()
#define ce(a) cout << (a) << endl
int main() {
  ll a, b, n;
  cin >> a >> b >> n;
  ll ans = 0;
  if (n >= b - 1) {
    ce(ll(a * (b - 1) / b) - a * ll((b - 1) / b));
  } else {
    ce(ll(a * (n) / b) - a * ll((n) / b));
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18;
typedef long long ll;
typedef vector<ll> vl;
#define rp(i, f, t) for (long long int i = f; i < t; i++)
#define pr(i, f, t) for (long long int i = t - 1; i >= f; i--)
#define ca(n, a)                                                               \\
  rp(ca_i, 0, n) cout << a[ca_i] << ((ca_i == n - 1) ? "\\n" : " ")
#define za(n, a) rp(za_i, 0, n) a[za_i] = 0
#define be(a) a.begin(), a.end()
#define ce(a) cout << (a) << endl
int main() {
  ll a, b, n;
  cin >> a >> b >> n;
  ll ans = 0;
  rp(i, 0, min(n, b) + 1) { ans = max(ans, ll(a * i / b) - a * ll(i / b)); }
  ce(ans);
}
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;

  long long ans = 0;

  if (n < b) {
    ans = (long long)(a * n / b) - a * (long long)(n / b);
  } else {
    if (n % b == 0) {
      ans = (long long)(a * (n - 1) / b) - a * (long long)((n - 1) / b);
    } else {
      ans = (long long)(a * (n - n % b - 1) / b) -
            a * (long long)((n - n % b - 1) / b);
    }
  }
  cout << ans << endl;
}


Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

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

  // for (int i = 1; i <= n; ++i){
  //     cout << i << " " << (long long)(a*i/b) - a*(long long)(i/b) << endl;
  // }

  // cout << "change" << endl;

  long long ans = 0;
  long long ans_cand;

  long long x;
  if (n < b) {
    x = n;
    ans = (long long)(a * x / b) - a * (long long)(x / b);
  } else {
    for (int i = (n - b) / b; i <= n / b; ++i) {
      if (i == 0) {
        x = n;
        ans = (long long)(a * x / b) - a * (long long)(x / b);
      } else {
        x = i * b - 1;
      }
      ans_cand = (long long)(a * x / b) - a * (long long)(x / b);
      if (ans < ans_cand) {
        ans = ans_cand;
      }
      // cout << x << " " << ans << endl;
    }
  }

  // ans = (long long)(a*n/b) - a*(long long)(n/b);
  cout << ans << endl;

  // long long ans = 0;
  // long long ans_cand;
  // for (int i = 0; i < n; ++i){
  //     ans_cand = floor(ax/b) - a * floor(x/b);
  //     if (ans <= ans_cand){
  //         ans = ans_cand;
  //     }
  // }
  // cout << ans << endl;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

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

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

Error: TLE

Fixed submission:

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

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

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rrep(i, n) for (int i = (int)(n); i >= 0; --i)
struct fast_ios {
  fast_ios() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} fast_ios_;

int main() {
  ll A, B, N;
  cin >> A >> B >> N;
  ll mx = A * (min(B - 1, N)) / B;

  // for(ll x=B-1;x<=N;++x)
  // {
  //     ll a = floorf64x(A*x/B) - A*floorf64x(x/B);
  //     mx = max(mx, a);
  // }
  cout << mx << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rrep(i, n) for (int i = (int)(n); i >= 0; --i)
struct fast_ios {
  fast_ios() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} fast_ios_;

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

#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int(i) = 0; i < (n); i++)
#define REP(i, m, n) for (int(i) = (m); (i) < (n); (i)++)
#define MOD 1000000007
#define fcout cout << fixed << setprecision(15)
#define int long long
#define yorn(f) puts((f) ? "Yes" : "No")
#define YORN(f) puts((f) ? "YES" : "NO")
typedef long long ll;
typedef pair<int, int> P;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; };
int lcm(int a, int b) { return a / gcd(a, b) * b; };
int mod(int a, int b) { return (a + b - 1) / b; };
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
  std::fill((T *)array, (T *)(array + N), val);
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
};
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
};

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

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

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int(i) = 0; i < (n); i++)
#define REP(i, m, n) for (int(i) = (m); (i) < (n); (i)++)
#define MOD 1000000007
#define fcout cout << fixed << setprecision(15)
#define int long long
#define yorn(f) puts((f) ? "Yes" : "No")
#define YORN(f) puts((f) ? "YES" : "NO")
typedef long long ll;
typedef pair<int, int> P;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; };
int lcm(int a, int b) { return a / gcd(a, b) * b; };
int mod(int a, int b) { return (a + b - 1) / b; };
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
  std::fill((T *)array, (T *)(array + N), val);
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
};
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
};

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

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

#include <algorithm>
#include <bits/stdc++.h>
#include <cstdio>
#include <functional>
#include <iostream>
#include <limits>
#include <numeric>
#include <queue>
#include <type_traits>
#include <vector>

using namespace std;
typedef long long ll;
#define rep(i, n, s) for (int i = s; i < (int)(n); i++)

ll calcNumOfCombination(ll n, ll r) {
  ll num = 1;
  for (ll i = 1; i <= r; i++) {
    num = num * (n - i + 1) / i;
  }
  return num;
}

int gcd(int x, int y) { return (x % y) ? gcd(y, x % y) : y; }

int findSumDigits(int s) {
  int num = 0;
  int temp = 0;
  while (s) {
    temp = s % 10;
    num += temp;
    s = s / 10;
  }
  return num;
}

int countDivisorNum(int n) {
  int count = 0;
  for (int i = 1; i <= n; i++) {
    if (n % i == 0) {
      count++;
    }
  }
  return count;
}

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

  ll temp1 = 0;
  ll temp2 = 0;
  //    ll temp3 = 0;
  //    ll temp = 0;
  if (n >= b) {
    temp1 = (a * (b - 1)) / b;
    temp2 = (a * ((b - 1) / b));
    ans = temp1 - temp2;
    //        for (n; n >= b - 1; n--) {
    //            temp1 = (a * n) / b;
    //            temp2 = (a * (n / b));
    //            temp3 = temp1 - temp2;
    //            if (temp3 >= ans) {
    //                ans = temp3;
    //            }
    //        }
  } else {
    temp1 = (a * n) / b;
    temp2 = (a * (n / b));
    ans = temp1 - temp2;
  }
  cout << ans << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <bits/stdc++.h>
#include <cstdio>
#include <functional>
#include <iostream>
#include <limits>
#include <numeric>
#include <queue>
#include <type_traits>
#include <vector>

using namespace std;
typedef long long ll;
#define rep(i, n, s) for (int i = s; i < (int)(n); i++)

ll calcNumOfCombination(ll n, ll r) {
  ll num = 1;
  for (ll i = 1; i <= r; i++) {
    num = num * (n - i + 1) / i;
  }
  return num;
}

int gcd(int x, int y) { return (x % y) ? gcd(y, x % y) : y; }

int findSumDigits(int s) {
  int num = 0;
  int temp = 0;
  while (s) {
    temp = s % 10;
    num += temp;
    s = s / 10;
  }
  return num;
}

int countDivisorNum(int n) {
  int count = 0;
  for (int i = 1; i <= n; i++) {
    if (n % i == 0) {
      count++;
    }
  }
  return count;
}

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

  ll temp1 = 0;
  ll temp2 = 0;
  ll temp3 = 0;
  for (n; n != 0; n--) {
    temp1 = (a * n) / b;
    temp2 = (a * (n / b));
    temp3 = temp1 - temp2;
    if (temp3 >= ans) {
      ans = temp3;
    }
  }

  cout << ans << endl;

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

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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main() {
  ll a, b, n;
  cin >> a >> b >> n;
  ll m = 0, x = min(b - 1, n), res = -1, count = 0;
  while (x >= 0) {
    res = a * x / b - a * (x / b);
    if (count > a)
      break;
    m = max(m, res);
    --x;
    ++count;
  }
  cout << m << endl;
  return 0;
}


Error: TLE

Fixed submission:

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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main() {
  ll a, b, n;
  cin >> a >> b >> n;
  ll m = 0, x = min(b - 1, n), res = -1;
  while (x >= 0) {
    res = a * x / b - a * (x / b);
    if (res < 0)
      break;
    m = max(m, res);
    --x;
  }
  cout << m << 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 ans = 0;

  long long x = B - 1;
  while (1) {
    if (x <= N)
      break;
    x--;
  }
  long long num1 = (A * x / B);
  long long num2 = (x / B);
  ans = num1 - A * num2;

  cout << ans << endl;
}

Error: TLE

Fixed submission:

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

int main() {

  long long A, B, N;
  cin >> A >> B >> N;

  long long ans = 0;

  for (int i = 0; i <= N; i++) {
    long long now = (A * i / B) - A * (i / B);
    ans = max(ans, now);
  }

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

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

int main(void) {
  ll A, B, N;

  cin >> A >> B >> N;

  ll c = 0;

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

  cout << c;
  return 0;
}

Error: TLE

Fixed submission:

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

int main(void) {
  ll A, B, N;

  cin >> A >> B >> N;

  ll c = 0;

  for (ll i = 0; i <= N; i++) {
    c = max(c, (A * i) / B - A * (i / B));
  }

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

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

inline void up(ll &x, ll y) { x < y ? x = y : 0; }

int main() {
  ll a, b, n, ans = 0;
  std::cin >> a >> b >> n;
  if (b - 1 <= n)
    std::cout << a * (b - 1) / b - a * ((b - 1) / b) << '\\n';
  else
    std::cout << a * n / b - a * (n / b) << '\\n';
  return 0;
}


Error: TLE

Fixed submission:

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

inline void up(ll &x, ll y) { x < y ? x = y : 0; }

int main() {
  ll a, b, n, ans = 0;
  std::cin >> a >> b >> n;
  for (ll x = 1; x <= n; ++x)
    up(ans, (a * x) / b - a * (x / b));
  std::cout << ans << '\\n';
  return 0;
}