alexjercan/bugnet huggingface dataset:
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 max = 0;

  max = a * n / b - a * (n / b);
  for (int i = n / b - 1; i >= 0; i--) {
    int64_t tmp = (b - 1) * (i + 1) * a / b - a * i;
    if (max < tmp) {
      max = tmp;
    }
  }

  cout << max << 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 max = 0;

  max = a * n / b - a * (n / b);
  for (int i = 0; i < n / b; i++) {
    int64_t tmp = (b - 1) * (i + 1) * a / b - a * i;
    if (max < tmp) {
      max = tmp;
      break;
    }
  }

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

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL << 62
#define inf 1000000007

int main() {
  ll a, b, n;
  cin >> a >> b >> n;
  if (n >= b - 1) {
    n = b - 1;
  }
  cout << (a * n) / b - a * (n / b);
  // your code goes here
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL << 62
#define inf 1000000007

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

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

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

  cin >> a >> b >> n;

  int max = 0;
  double temp = min(b - 1, n);
  // for (double i = 0; i <= temp; i++)
  // {
  int v = floor(a * temp / b) - a * floor(temp / b);
  //   if (max < v)
  //     max = v;
  // }
  cout << v << endl;
}

Error: TLE

Fixed submission:

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

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

  cin >> a >> b >> n;

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

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

#define pb push_back
#define mp make_pair
#define prior priority_queue
#define MOD 1000000007
#define INF (long long int)9e18
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define ll long long int
#define ld long double
#define ret return
#define NUM 1000001
const int SIZE = 2e5 + 4;
void fastio() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}

void input() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
}

int main() {
  fastio();
  input();

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


Error: TLE

Fixed submission:

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

#define pb push_back
#define mp make_pair
#define prior priority_queue
#define MOD 1000000007
#define INF (long long int)9e18
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define ll long long int
#define ld long double
#define ret return
#define NUM 1000001
const int SIZE = 2e5 + 4;
void fastio() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}

void input() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
}

int main() {
  fastio();
  input();

  ll a, b, n;
  cin >> a >> b >> n;
  ll max = 0;
  for (ll i = 1; i <= n; i++) {
    ll d = floor((a * i) / (float)b) - a * floor(i / (float)b);
    if (d > max) {
      max = d;
    }
  }
  cout << max << endl;

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

#include <algorithm>
#include <assert.h>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <vector>
using namespace std;
#define ll long long int
int main() {
  ll A, B, N;
  cin >> A >> B >> N;
  ll ans;
  ll r;
  if (N < B)
    r = N;
  else
    r = B - 1;
  ans = (A / B) * r + floor((double(A % B) / B) * r);
  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <assert.h>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <vector>
using namespace std;

int main() {
  long long int A, B, N;
  cin >> A >> B >> N;
  long long int ans;
  long long int x = 1;
  long long int max = 0;

  while (x <= N) {
    ans = floor(float(A * x) / B) - A * (floor(float(x) / B));
    if (max < ans)
      max = ans;
    x++;
  }
  cout << max << endl;
  return 0;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

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

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

Error: TLE

Fixed submission:

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

long A, B, N;
long ans = 0;

long compute(long x) { return (A * x) / B - A * (x / B); }

long solve(long i) {
  if (i > N) {
    ans = max(ans, compute(N));
    return ans;
  }
  if (i != -1)
    ans = max(ans, compute(i));
  i += B;
  return solve(i);
}

int main() {
  cin >> A >> B >> N;
  cout << solve(-1) << endl;
  return 0;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <malloc.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>

typedef long long int64;
typedef unsigned long long uint64;

#define min(a, b) (((a) < (b)) ? (a) : (b))

int main() {

  uint64 a, b, n;

  scanf("%llu %llu %llu", &a, &b, &n);

  printf("%llu", (uint64)floor(a * min(b - 1, n) / b));

  return 0;
}


Error: TLE

Fixed submission:

#include <stdio.h>

typedef long long int64;
typedef unsigned long long uint64;

int main() {
  uint64 a, b, n;
  uint64 i, j = 0;

  scanf("%llu %llu %llu", &a, &b, &n);

  for (uint64 x = 1; x <= n; x++) {
    i = (a * x / b) - a * (x / b);
    if (i > j) {
      j = i;
    }
  }

  printf("%llu", j);

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

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

using namespace std;

int main() {
  ll a, b, n;
  scanf("%lld %lld %lld", &a, &b, &n);
  if (b <= n)
    n = n / b * b - 1;
  printf("%lld\\n", a * n / b - a * (n / b));
}

Error: 0

Fixed submission:

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

using namespace std;

int main() {
  ll a, b, n;
  scanf("%lld %lld %lld", &a, &b, &n);
  if (n % b == 0)
    b--;
  printf("%lld\\n", a * n / b - a * (n / b));
}
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 ALL(n) begin(n), end(n)

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

  // int max = 0;
  // ll tmp;
  // REP(i, n){
  //   tmp = floor(a*(i+1)/b) - a * floor((i+1)/b);
  //   if(max < tmp) max = tmp;
  // }

  ll x;
  if (b > n) {
    x = n;
  } else {
    x = b - 1;
  }

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

  cout << ans << endl;
}

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 ALL(n) begin(n), end(n)

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

  int max = 0;
  ll tmp;
  REP(i, n) {
    tmp = floor(a * (i + 1) / b) - a * floor((i + 1) / b);
    if (max < tmp)
      max = tmp;
  }

  cout << max << endl;
}
Problem p02696 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
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;
}
int main() {
  ios::sync_with_stdio(false);
  ll a, b, n;
  ll max = 0;
  cin >> a >> b >> n;
  if (n <= b - 1)
    max = (a * n) / b;
  else
    max = (a * (b - 1)) / b;
  cout << max << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
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;
}
int main() {
  ios::sync_with_stdio(false);
  ll a, b, n;
  ll max = 0;
  cin >> a >> b >> n;
  if (n <= b)
    max = (a * n) / b;
  else
    max = (a / (b - 1)) / b;
  cout << max << endl;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <iostream>
#include <list>
#include <set>
#include <vector>

#define ll long long

using namespace std;

int main() {
  ll a, b, n;
  ll fx;
  ll res = 0;
  cin >> a >> b >> n;
  /*	for (int x = 0; x <= (n<b?n:b); ++x) {
                  cout << "x = " << x << ends;
                  fx = floor(a * x / b) - a * floor(x / b);
                  cout << "f(x) = " << fx << endl;
                  res = max(res, fx);
          }
          */
  if (n < b)
    fx = floor(a * n / b) - a * floor(n / b);
  else
    fx = floor(a * (b - 1) / b) - a * floor((b - 1) / b);
  cout << fx << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <list>
#include <set>
#include <vector>

#define ll long long

using namespace std;

int main() {
  ll a, b, n;
  ll fx;
  ll res = 0;
  cin >> a >> b >> n;
  for (int x = 0; x <= (n < b ? n : b); ++x) {
    // cout << "x = " << x << ends;
    fx = floor(a * x / b) - a * floor(x / b);
    // cout << "f(x) = " << fx << endl;
    res = max(res, fx);
  }
  cout << res << endl;
  return 0;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

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

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

Error: TLE

Fixed submission:

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

int main() {
  ll A, B, N, m = 0, h = 0;
  cin >> A >> B >> N;
  for (int i = 0; i <= N; i++) {
    h = (A * i / B) - A * (i / B);
    m = max(h, m);
  }
  cout << m << 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++)
int64_t MOD = 1000000007;
const long long INF = 1LL << 60;

int main() {
  int64_t A, B, N;
  cin >> A >> B >> N;
  auto k = min(B - 1, N);
  cout << floor(A * k / B) - A * floor(k / B);
}


Error: TLE

Fixed submission:

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

int main() {
  int64_t A, B, N;
  cin >> A >> B >> N;
  double total = 0;
  for (int64_t i = N; i > N - 1000000000; i--) {
    if (i < 1)
      break;
    double a, b;
    a = A * i / B;
    b = i / B;

    total = max(total, floor(a) - A * floor(b));
  }
  cout << total;
}
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;
  int maxx = 0;

  long long int i = min(b - 1, n);

  cout << (a * i) / b - a * (i / b) << "\\n";

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

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

  for (int i = 1; i <= min(b, n); i++) {
    if (((a * i) / b - a * (i / b)) > maxx)
      maxx = ((a * i) / b - a * (i / b));
  }

  cout << maxx << "\\n";

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

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
int main() {
  ll A, B, N;
  cin >> A >> B >> N;
  if (B <= N)
    cout << (A * (B - 1)) / B << endl;
  else {
    cout << (A * N) / B << endl;
  }
}


Error: TLE

Fixed submission:

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

int main() {
  ll A, B, N;
  cin >> A >> B >> N;
  ll max = 0;
  for (ll i = 1; i <= N; i++) {
    if ((A * i) / B - A * (i / B) > max) {
      max = (A * i) / B - A * (i / B);
    }
  }
  cout << max << endl;
}
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 < n; i++)
using ll = long long;
using P = pair<ll, ll>;

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

Error: TLE

Fixed submission:

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

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

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

int main() {
  double a, b, n;
  cin >> a >> b >> n;
  double e, f;
  e = min(b - 1, n);
  f = floor((a * e) / b) - a * floor(e / b);
  cout << f << endl;
}

Error: TLE

Fixed submission:

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

int main() {
  float a, b, n;
  cin >> a >> b >> n;
  float e, f;
  for (float i = 0; i < n + 1; i++) {
    f = floor((a * i) / b) - a * floor(i / b);
    e = max(e, f);
  }
  cout << e << endl;
}
Problem p02696 (C++) — buggy submission, verdict: Runtime Error

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

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

  n = min(n, b - 1);

  std::cout << a * n / b - a * (n / b) << std::endl;
}


Error: 0

Fixed submission:

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

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

  ll ta = a % b;
  ld ans = 0;
  if (n >= b) {
    ll target = b / ta * (ta - 1);
    for (int i = -1000; i < 1000; i++) {
      ll x = target + i;
      if (target + i >= 0 && target + i <= b) {
        ans = max(ans, floor(a * x * 1.0 / b) - a * floor(x * 1.0 / b));
      }
    }
    std::cout << ans << std::endl;
  } else {
    ll pos = 0;
    if (ta != 0)
      pos = n / ta;
    for (int i = -1000; i < 1000; i++) {
      ll x = pos + i;
      if (x >= 0 && x <= n) {
        ans = max(ans, floor(a * x * 1.0 / b) - a * floor(x * 1.0 / b));
      }
    }
    std::cout << ans << std::endl;
  }
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

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

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
  ll A, B, N, ans = 0;
  cin >> A >> B >> N;
  ll c = N / B;
  if (c == 0) {
    cout << (A * N) / B - A * (N / B) << endl;
  } else {
    for (ll i = 0; i < c; i++) {
      ans = max((A * (B * (i + 1) - 1)) / B - A * ((i + 1) / B), ans);
    }
    if (B * (c + 1) - 1 == N) {
      ll memo = ans;
      ans = max((A * (B * (c + 1) - 1)) / B - A * ((c + 1) / B), ans);
      if (ans - memo < 0) {
        return 0;
      }
    }
    cout << ans << endl;
  }
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>

int main(int argc, const char *argv[]) {
  long long int a, b, n, c;
  c = 0;
  std::cin >> a >> b >> n;
  if (b > n) {
    std::cout << a * n / b - a * (n / b) << std::endl;
  } else {
    c = (n / b) * b - 1;
    std::cout << a * c / b - a * (c / b) << std::endl;
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>

int main(int argc, const char *argv[]) {
  long long int a, b, n, c;
  c = 0;
  std::cin >> a >> b >> n;
  if (b > n) {
    std::cout << a * n / b - a * (n / b) << std::endl;
  } else {
    for (int i = 1; i * b - 1 < n; i++) {
      c = i * b - 1;
    }
    std::cout << a * c / b - a * (c / b) << std::endl;
  }
  return 0;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

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

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

Error: TLE

Fixed submission:

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

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

#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <functional>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <vector>
#define _USE_MATH_DEFINES
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <set>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (auto i = a; i < b; i++)
#define all(_x) _x.begin(), _x.end()
#define r_sort(_x) sort(_x.begin(), _x.end(), std::greater<int>())
#define vec_cnt(_a, _n) (upper_bound(all(_a), _n) - lower_bound(all(_a), _n))
ll gcd(ll a, ll b) { return a % b == 0 ? b : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
#define INF 1 << 30
const ll mod = 1000000007;
int main() {
  ll A, B, N, x = 1, M = 0, c = 1;
  scanf("%lld%lld%lld", &A, &B, &N);

  if (B == 1) {
    puts("0");
    return 0;
  }
  if (N < 100000) {
    while (x <= N) {
      M = max(M, A * x / B - A * (x / B));
      x++;
    }
  } else {
    c = max((N - 10000000) / B, 0ll);
    while ((x = B * c - 1) <= N) {
      M = max(M, A * x / B - A * (x / B));
      c++;
    }
    x = max(N - 100000, 0ll);
    while (x <= N) {
      M = max(M, A * x / B - A * (x / B));
      x++;
    }
  }
  printf("%lld\\n", M);
  return 0;
}


Error: TLE

Fixed submission:

#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <functional>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <vector>
#define _USE_MATH_DEFINES
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <set>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (auto i = a; i < b; i++)
#define all(_x) _x.begin(), _x.end()
#define r_sort(_x) sort(_x.begin(), _x.end(), std::greater<int>())
#define vec_cnt(_a, _n) (upper_bound(all(_a), _n) - lower_bound(all(_a), _n))
ll gcd(ll a, ll b) { return a % b == 0 ? b : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
#define INF 1 << 30
const ll mod = 1000000007;
int main() {
  ll A, B, N, x = 1, M = 0, c = 1;
  scanf("%lld%lld%lld", &A, &B, &N);

  if (B == 1) {
    puts("0");
    return 0;
  }
  if (N < 100000) {
    while (x <= N) {
      M = max(M, A * x / B - A * (x / B));
      x++;
    }
  } else {
    c = max((N - 10000000) / B, 0ll);
    while ((x = B * c - 1) <= N) {
      M = max(M, A * x / B - A * (x / B));
      c++;
    }
    x -= B;
    while (x <= N) {
      M = max(M, A * x / B - A * (x / B));
      x++;
    }
  }
  printf("%lld\\n", M);
  return 0;
}
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 x, maxi = 0;
  int64_t p = min(b - 1, n);
  int64_t q = p / b;
  int64_t ans = a * p / b - a * q;
  cout << ans;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int64_t a, b, n;
  cin >> a >> b >> n;
  int64_t x, maxi = 0;
  for (x = 0; x <= n; x++) {
    int64_t p = x / b;
    int64_t ans = a * x / b - a * p;
    maxi = max(ans, maxi);
  }
  cout << maxi;
}
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 < n; i++)
#define rep1(i, n) for (int i = 1; i < n + 1; i++)
#define sort(A) sort(A.begin(), A.end())
#define reverse(A) reverse(A.begin(), A.end());
typedef long long ll;

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


Error: TLE

Fixed submission:

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

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

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

#define lld long long
#define pi pair<int, int>
#define pl pair<lld, lld>
#define mem0(x) memset(x, 0, sizeof(x))
#define fillnum(x, n) fill(begin(x), end(x), n)
#define asort(x) sort(x.begin(), x.end())
#define dsort(x, t) sort(x.begin(), x.end(), greater<t>())

int main() {
  lld A, B, N;
  cin >> A >> B >> N;
  lld maxv = -1;
  lld nowx = max(0LL, N - 10 * B);
  while (true) {
    if (nowx > N) {
      cout << maxv << endl;
      exit(0);
    }
    lld left = (A * nowx / B);
    lld right = A * (nowx / B);
    // cout << left << " " << right << endl;
    maxv = max(maxv, left - right);
    nowx = min(((left + 1) * B / A) + 1, (right + 1) * B);
    // cout << ((left + 1) * B / A) + 1 << " " << (right + 1) * B << endl;
    // cout << nowx << endl;
  }
}

Error: TLE

Fixed submission:

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

#define lld long long
#define pi pair<int, int>
#define pl pair<lld, lld>
#define mem0(x) memset(x, 0, sizeof(x))
#define fillnum(x, n) fill(begin(x), end(x), n)
#define asort(x) sort(x.begin(), x.end())
#define dsort(x, t) sort(x.begin(), x.end(), greater<t>())

int main() {
  lld A, B, N;
  cin >> A >> B >> N;
  lld maxv = -1;
  lld nowx = N / 2;
  while (true) {
    if (nowx > N) {
      cout << maxv << endl;
      exit(0);
    }
    lld left = (A * nowx / B);
    lld right = A * (nowx / B);
    // cout << left << " " << right << endl;
    maxv = max(maxv, left - right);
    nowx = min(((left + 1) * B / A) + 1, (right + 1) * B);
    // cout << ((left + 1) * B / A) + 1 << " " << (right + 1) * B << endl;
    // cout << nowx << endl;
  }
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

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

const long INF = 1L << 60;

int main() {
  long a, b, n;
  scanf("%ld%ld%ld", &a, &b, &n);
  if (b - 1 >= n)
    printf("%ld\\n", (long)(floor(a * n / b) - a * floor(n / b)));
  else
    printf("%ld\\n", (long)(floor(a * (b - 1) / b) - a * floor((b - 1) / b)));
}


Error: TLE

Fixed submission:

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

const long INF = 1L << 60;

int main() {
  long a, b, n;
  scanf("%ld%ld%ld", &a, &b, &n);
  long ans = -INF;
  for (int i = n / 2; i <= n; i++)
    ans = max(ans, (long)(floor(a * i / b) - a * floor(i / b)));
  printf("%ld\\n", 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 x = min(n, b - 1);
  cout << (a * x) / b - a * (x / b) << 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 m = -1010101010;
  for (int x = 0; x <= n; x++) {
    long long num = a * x / b - a * (x / b);
    m = max(m, num);
  }
  cout << m << endl;
}