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

#include <iostream>
#define min(a, b) ((a) > (b)) ? (b) : (a)
typedef long long ll;

using namespace std;

ll f(ll r, ll a, ll b) { return a * r / b; }

int main() {
  ll a, b, n, ans;
  cin >> a >> b >> n;
  ans = f(min(b - 1, n), a, b);
  cout << ans << endl;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#define rep(a, i, n) for (int i = (a); i < (n); i++)
typedef long long ll;

using namespace std;

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

#include <cmath>
#include <iostream>
using namespace std;
int main() {
  long long int a, b, n, i, max = 0, temp = 0;
  cin >> a >> b >> n;
  if (b - 1 <= n)
    max = floor((b - 1) * a / b) - a * floor((b - 1) / b);
  else
    max = floor(n * a / b) - a * floor(n / b);
  cout << max << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <cmath>
#include <iostream>
using namespace std;
int main() {
  long long int a, b, n, i, max = 0, temp = 0;
  cin >> a >> b >> n;
  for (i = 1; ((i <= n) && (i <= b)); i++) {
    temp = floor(a * i / b) - a * floor(i / b);
    if (temp > max)
      max = temp;
    if (temp < max)
      break;
  }
  cout << max << 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;

  if (B == 1) { // B = 1の時は計算しない
    cout << 0 << endl;
    return 0;
  }

  // xはBの倍数-1だけ試す
  long long x = B - 1;
  int i = 1;
  int ans = 0;

  if (B > N) {
    ans = (A * N) / B - A * (x / B);

    cout << ans << endl;

    return 0;
  }

  while (x <= N) {

    int TRY;

    TRY = (A * x) / B - A * (x / B);

    ans = max(ans, TRY);

    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;

  // xはBの倍数-1だけ試す
  long long x = B - 1;
  int i = 1;
  int ans = 0;

  if (B > N) {
    ans = (A * N) / B - A * (x / B);

    cout << ans << endl;

    return 0;
  }

  while (x <= N) {

    int TRY;

    TRY = (A * x) / B - A * (x / B);

    ans = max(ans, TRY);

    i++;

    x = B * i - 1;
  }

  cout << ans << endl;

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

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

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

Error: TLE

Fixed submission:

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

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

  while (1) {
    temp = floor(a * x / b) - a * floor(x / b);
    if (ans < temp)
      ans = temp;
    x--;
    if (x != b && ans > temp)
      break;
  }
  cout << ans << endl;
  return 0;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#define ll long long
#define ull unsigned long long
#define dd double
#define oo 1001007000
#define ff float
#define ooo 4223352036854775007
#define iii pair<ll, ll>
#define vii vector<ll>
#define viii vector<iii>
#define sss pair<str, str>
#define str string
#define sii set<ll>
#define siii set<iii>
#define r0 return 0
#define pb push_back
#define sz size
using namespace std;

const char E = '\\n';
const int N = 10005;
const int NN = 2005;
const ll md = 998244353;

int main() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(0);
  ll a, b, n;
  cin >> a >> b >> n;
  ll ans = (a * n) / b - a * (n / b);
  for (ll i = n - 1; i >= max(n - 10000000, 1ll); i--) {
    ans = max(ans, (a * i) / b - a * (i / b));
  }
  for (ll i = 1; i <= min(n, 10000000ll); i++) {
    ans = max(ans, (a * i) / b - a * (i / b));
  }
  for (ll i = b - 10000000; i <= b + 10000000; i++) {
    if (i <= 0 || i > n)
      continue;
    ans = max(ans, (a * i) / b - a * (i / b));
  }
  cout << ans << E;
  r0;
}
/*









*/


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#define ll long long
#define ull unsigned long long
#define dd double
#define oo 1001007000
#define ff float
#define ooo 4223352036854775007
#define iii pair<ll, ll>
#define vii vector<ll>
#define viii vector<iii>
#define sss pair<str, str>
#define str string
#define sii set<ll>
#define siii set<iii>
#define r0 return 0
#define pb push_back
#define sz size
using namespace std;

const char E = '\\n';
const int N = 10005;
const int NN = 2005;
const ll md = 998244353;

int main() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(0);
  ll a, b, n;
  cin >> a >> b >> n;
  ll ans = (a * n) / b - a * (n / b);
  for (ll i = n - 1; i >= max(n - 100000000, 1ll); i--) {
    ans = max(ans, (a * i) / b - a * (i / b));
  }
  for (ll i = 1; i <= min(n, 100000000ll); i++) {
    ans = max(ans, (a * i) / b - a * (i / b));
  }
  cout << ans << E;
  r0;
}
/*









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

#include <bits/stdc++.h>
#define speed                                                                  \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
#pragma GCC optimize "-O3"
#define int long long

using namespace std;

const int N = 1e4 + 7;
const int mod = 1e9 + 7;

void solve() {
  int a, b, n, ans = 0;
  cin >> a >> b >> n;
  for (int x = 0; x < min(10000000ll, n); x++) {
    ans = max(ans, (a * x) / b - a * (x / b));
  }
  for (int x = 0; x <= n; x += 10000) {
    ans = max(ans, (a * x) / b - a * (x / b));
  }

  for (int x = n; x > max(n - 10000000ll, 0ll); x--) {
    ans = max(ans, (a * x) / b - a * (x / b));
  }
  cout << ans;
}

int32_t main() {
  speed;
  int T = 1;
  // cin >> T;
  while (T--) {
    solve();
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define speed                                                                  \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
#pragma GCC optimize "-O3"
#define int long long

using namespace std;

const int N = 1e4 + 7;
const int mod = 1e9 + 7;

void solve() {
  int a, b, n, ans = 0;
  cin >> a >> b >> n;
  for (int x = 0; x < min(60000000ll, n); x++) {
    ans = max(ans, (a * x) / b - a * (x / b));
  }
  for (int x = 60000000ll; x < min(60000000ll + 60000000ll, n); x++) {
    ans = max(ans, (a * x) / b - a * (x / b));
  }

  for (int x = n; x > max(n - 60000000ll, 0ll); x--) {
    ans = max(ans, (a * x) / b - a * (x / b));
  }
  cout << ans;
}

int32_t main() {
  speed;
  int T = 1;
  // cin >> T;
  while (T--) {
    solve();
  }
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

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

ll min1(ll a, ll b) {
  if (a > b) {
    return b;
  } else {
    return a;
  }
}

int main() {
  ll A, B, N;
  cin >> A >> B >> N;
  ll x = min1(B - 1, N);
  ll ans = (A * x) / B - A * (x / B);

  cout << ans << endl;
}


Error: TLE

Fixed submission:

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

ll max1(ll a, ll b) {
  if (a > b) {
    return a;
  } else {
    return b;
  }
}

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

  for (ll j = 1; j <= N; j++) {
    i = floor((A * j) / B) - A * floor(j / B);
    if (i == 0 && check != 0) {
      cout << check << endl;
      return 0;
    }
    check = max1(i, check);
    //	cout <<j << ":" << check << endl;
  }
  cout << check << endl;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  long long int ans = 0, n, x, t, a, b;
  scanf("%lld %lld %lld", &a, &b, &n);
  long long p = min(b - 1, n);

  printf("%lld", (a * p) / b - a * (p / b));
}

Error: TLE

Fixed submission:

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

int main() {
  long long int ans = 0, n, x, t, p, a, b;
  scanf("%lld %lld %lld", &a, &b, &n);
  for (int i = 0; i <= n; i++) {
    long long g = i / b;
    g *= a;
    long long f = a * i;
    f /= b;
    ans = max(ans, f - g);
  }
  printf("%lld", ans);
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

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

long long calc(long long i) {
  long double res = floor(a * i / b) - a * floor(i / b);
  return res;
}

int main() {
  long long n;
  cin >> a >> b >> n;
  cout << calc(min(b - 1, n)) << endl;
}


Error: TLE

Fixed submission:

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

long long a, b, rem;
long long calc() {
  long long res = floor(a * rem / b) - a * floor(rem / b);
  return res;
}

int main() {
  long long n;
  cin >> a >> b >> n;
  long long max = 0;
  long long u = 0;
  for (rem = 0; rem <= n; rem++) {
    u = calc();
    if (u > max) {
      max = u;
      if (max == a - 1) {
        break;
      }
    }
  }
  cout << max << endl;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;

int main() {
  long long int a, b, n;
  cin >> a >> b >> n;
  long long int x;
  long long int maks = 0;
  if (b > n) {
    x = n;
    long long int prv = (a * x) / b;
    long int vtor = x / b;
    cout << prv - a * vtor << endl;
  } else {
    x = b - 1;
    long long int prv = (a * x) / b;
    long int vtor = x / b;
    cout << prv - a * vtor << endl;
  }
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

int main() {
  long long int a, b, n;
  cin >> a >> b >> n;
  long long int x;
  long long int maks = 0;
  if (b > n) {
    x = n;
    long long int prv = (a * x) / b;
    long int vtor = x / b;
    cout << prv - a * vtor << endl;
    return 0;
  } else {
    for (long long int i = n; i >= (b - 1); i--) {
      x = i;
      long long int prv = (a * x) / b;
      long int vtor = x / b;
      long long int rez = prv - a * vtor;
      if (rez > maks) {
        maks = rez;
      }
    }
  }
  cout << maks << endl;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;
const int INF = 1e9 + 5;
typedef long long ll;
const int MOD = 1e9 + 7;
int main() {
  ll a, b, n;
  cin >> a >> b >> n;
  // ll maxi=INT_MIN;
  ll ans;
  if (b <= n)
    ans = (a * (b - 1)) / b;
  else
    ans = (a * n) / b;
  cout << ans << endl;

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
const int INF = 1e9 + 5;
typedef long long ll;
const int MOD = 1e9 + 7;
int main() {
  ll a, b, n;
  cin >> a >> b >> n;
  ll maxi = INT_MIN;
  int j = 1;
  if (j > 100000000)
    j = 100000000;
  for (ll i = j; i <= n; i++) {
    maxi = max(maxi, ((a * i) / b) - a * (i / b));
  }
  cout << maxi << endl;

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

#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <vector>

using namespace std;

void C(void) {
  long long n, m, q;
  long long i, j, k;
  long long temp_a, temp_b, temp_c, temp_d;
  vector<long long> a, b, c, d;

  cin >> n >> m >> q;

  for (i = 0; i < q; i++) {
    cin >> temp_a, temp_b, temp_c, temp_d;
    a.push_back(temp_a);
    b.push_back(temp_b);
    c.push_back(temp_c);
    d.push_back(temp_d);
  }
}

int main(void) {
  long long n, m, q;
  long long i, j, k;
  long long a, b;
  long long max = 0;

  cin >> a >> b >> n;

  if (b > n) {
    max = floor((a * n) / double(b)) - a * floor(n / double(b));
  } else {
    max = floor((a * (b - 1)) / double(b)) - a * floor((b - 1) / double(b));
  }

  cout << max << endl;

  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <vector>

using namespace std;

void C(void) {
  long long n, m, q;
  long long i, j, k;
  long long temp_a, temp_b, temp_c, temp_d;
  vector<long long> a, b, c, d;

  cin >> n >> m >> q;

  for (i = 0; i < q; i++) {
    cin >> temp_a, temp_b, temp_c, temp_d;
    a.push_back(temp_a);
    b.push_back(temp_b);
    c.push_back(temp_c);
    d.push_back(temp_d);
  }
}

int main(void) {
  long long n, m, q;
  long long i, j, k;
  long long a, b;
  long long max = 0;

  cin >> a >> b >> n;

  for (i = 0; i <= n; i++) {
    m = floor((a * i) / double(b)) - a * floor(i / double(b));
    if (max < m) {
      max = m;
    }
  }

  cout << max << endl;

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

#include <bits/stdc++.h>
using namespace std;
const long long INF = 1LL << 60;
const int mod = 1e9 + 7;

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

  long long x = 0;
  long long ans = 0;

  if (b > n) {
    x = n;
    ans = a * x / b;
  } else {

    ans = (int)((double)a * (double)(b - 1) / (double)b);
  }

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

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
const long long INF = 1LL << 60;
const int mod = 1e9 + 7;

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

  long long x = 0;
  long long ans = 0;

  if (b > n) {
    x = n;
    ans = a * x / b;
  } else {
    double M = 0;
    for (int i = 1; i < b; i++) {
      double num = (double)i / (double)b;
      if (M < num) {
        M = num;
        x = i;
      }
    }
    ans = (int)((double)a * M);
  }

  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<int, int>;

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


Error: TLE

Fixed submission:

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

int main() {
  long double a, b;
  ll ma = 0, w, n;
  cin >> a >> b >> n;
  rep(i, n + 1) {
    w = floor(a * i / b) - a * floor(i / b);
    if (ma > w)
      break;
    ma = w;
  }
  cout << ma << endl;
}
Problem p02696 (C++) — buggy submission, verdict: Runtime Error

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

typedef long long ll;

int main() {
  ios_base::sync_with_stdio(false);

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

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

  cout << a * x / b << endl;
}


Error: 0

Fixed submission:

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

typedef long long ll;

int main() {
  ios_base::sync_with_stdio(false);

  ll a, b, n;
  while (cin >> a >> b >> n) {

    ll ans = 0, cur, t = n / abs(a - b);

    for (int i = 0; i <= 100; i++) {
      ll x;
      x = t + i;
      x = min(n, x);

      cur = (a * x / b) - (a * (x / b));

      ans = max(ans, cur);

      x = t - i;
      x = max(0LL, x);

      cur = (a * x / b) - (a * (x / b));

      ans = max(ans, cur);
    }

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

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18, MOD = 1e9 + 7;
const int INT_INF = 1e9, INT_MOD = 1e9 + 7;
#define rep(i, N) for (int i = 0; i < N; i++)
typedef pair<int, int> Pi;
typedef pair<double, double> P;

signed main() {
  ll a, b, n;
  cin >> a >> b >> n;
  ll maxa = (a * n) / b, maxb = n / b;
  ll tmax = maxa - a * maxb;
  if (n % b == 0) {
    ll tmpa = (a * (n - 1)) / b, tmpb = (n - 1) / b;
    cout << tmpa - a * tmpb << endl;
  } else {
    ll tmp = (n / b) * b - 1;
    ll tmpa = (a * tmp) / b, tmpb = tmp / b;
    cout << max(tmpa - a * tmpb, tmax) << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18, MOD = 1e9 + 7;
const int INT_INF = 1e9, INT_MOD = 1e9 + 7;
#define rep(i, N) for (int i = 0; i < N; i++)
typedef pair<int, int> Pi;
typedef pair<double, double> P;

signed main() {
  ll a, b, n;
  cin >> a >> b >> n;
  ll maxa = (a * n) / b, maxb = n / b;
  ll tmax = maxa - a * maxb;
  for (ll i = n;; i--) {
    if ((i + 1) % b == 0) {
      ll tmpa = (a * i) / b, tmpb = i / b;
      cout << max(tmax, tmpa - a * tmpb) << endl;
      break;
    }
  }
  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<int, int>;

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


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;
  int max_val = 0;
  for (int x = 0; x <= n; ++x) {
    int val = floor(a * x / b) - a * floor(x / b);
    max_val = max(max_val, val);
  }
  cout << max_val << endl;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

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

#define ll long long
#define ld long long
#define pi 3.14159265359

int main() {
  ll A, B, N;
  cin >> A >> B >> N;
  ll m;
  if (N < B) {
    m = (A * N) / B - A * (N / B);
  } else {
    m = (A * (B - 1)) / B - A * ((B - 1) / B);
  }
  cout << m << endl;
}

Error: TLE

Fixed submission:

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

#define ll long long
#define ld long long
#define pi 3.14159265359

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

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

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

  if (b - 1 < n) {
    cout << floor(a * (b - 1) / b) - a * floor((b - 1) / b) << endl;
  } else {
    cout << floor(a * n / b) - a * floor(n / b) << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

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

int kansuu(long int a, long int b, long int x) {
  long int sum;
  sum = a * x / b - (a * (x / b));
  return sum;
}
int main() {
  long int a, b, n;
  long int max = 0;
  cin >> a >> b >> n;

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

#define _USE_MATH_DEFINES
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <random>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define fcout cout << fixed << setprecision(10)
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define mp(a, b) make_pair(a, b)
#define pb push_back
#define all(x) x.begin(), x.end()
const ll inf = 1e18;
const ll mod = 1e9 + 7;

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

// mod. m での a の逆元 a^(-1) を計算する。
ll modinv(ll a, ll m) {
  ll b = m, u = 1, v = 0;
  while (b) {
    ll t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= m;
  if (u < 0)
    u += m;
  return u;
}

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


Error: TLE

Fixed submission:

#define _USE_MATH_DEFINES
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <random>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define fcout cout << fixed << setprecision(10)
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define mp(a, b) make_pair(a, b)
#define pb push_back
#define all(x) x.begin(), x.end()
const ll inf = 1e18;
const ll mod = 1e9 + 7;

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

// mod. m での a の逆元 a^(-1) を計算する。
ll modinv(ll a, ll m) {
  ll b = m, u = 1, v = 0;
  while (b) {
    ll t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= m;
  if (u < 0)
    u += m;
  return u;
}

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

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

void solve(long long A, long long B, long long N) {
  ll mae, ato;
  ll x, ans;
  if (N >= B)
    x = B - 1;
  else {
    x = N;
  }
  mae = (A * x) / B;
  ato = A * ll(x / B);
  ans = ll(mae) - ll(ato);

  cout << ans << endl;
}

int main() {
  long long A;
  scanf("%lld", &A);
  long long B;
  scanf("%lld", &B);
  long long N;
  scanf("%lld", &N);
  solve(A, B, N);
  return 0;
}


Error: TLE

Fixed submission:

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

void solve(long long A, long long B, long long N) {
  ll answer = 0, ans, mae, a, ato;
  for (ll i = 1; i <= N; i++) {
    mae = (A * i) / B;
    a = i / B;
    ato = A * ll(a);
    ans = ll(mae) - ato;
    answer = max(answer, ans);
  }
  cout << answer << endl;
}

int main() {
  long long A;
  scanf("%lld", &A);
  long long B;
  scanf("%lld", &B);
  long long N;
  scanf("%lld", &N);
  solve(A, B, N);
  return 0;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <math.h>

using namespace std;

int main() {
  long a, b, n, x, tmp, max = 0;
  cin >> a >> b >> n;

  x = b - 1;
  if (b > n)
    x = n;

  cout << floorl(a * x / b) - a * floorl(x / b);
  ;
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <math.h>

using namespace std;

int main() {
  long a, b, n, x, tmp, max = 0;
  cin >> a >> b >> n;

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

  cout << max;
  return 0;
}