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

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb(x) push_back(x)

int main() {

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

    } else {
      ll i = b - 1;
      ll p = (ll)((a * i) / b) - (ll)(a * (ll)(i / b));
      cout << p << endl;
    }
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb(x) push_back(x)

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

  ll mx = -2;
  for (ll i = 1; i <= n; i++) {
    ll p = (ll)((a * i) / b) - (ll)(a * (ll)(i / b));
    //        cout<<i<<"=>"<<p<<endl;
    mx = max(p, mx);
  }
  cout << mx << endl;
  return 0;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#pragma GCC optimize("O2")
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define endl "\\n"
#define sz(u) (int)(u.size())
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
void solve() {
  double a, b, n;
  cin >> a >> b >> n;
  if (n < b) {
    /*int maxx=0;
for(int i=1;i<=n;i++){
    maxx=max(maxx,int(floor(a*i/b)-a*(floor(i/b))));
}
cout<<maxx<<endl;
*/
    cout << floor(a * n / b);
  } else {
    cout << int(floor(a * (b - 1) / b));
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  solve();
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#pragma GCC optimize("O2")
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define endl "\\n"
#define sz(u) (int)(u.size())
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
void solve() {
  double a, b, n;
  cin >> a >> b >> n;
  int x = 1;
  if (n < b) {
    int maxx = 0;
    for (int i = 1; i <= n; i++) {
      maxx = max(maxx, int(floor(a * i / b) - a * (floor(i / b))));
    }
    cout << maxx << endl;
  } else {
    cout << int(floor(a * (b - 1) / b));
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  solve();
}
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;

  // f(x) = floor(Ax / B) - A * floor(x / B)とおく
  // f(x + B) = f(x)が成り立つ
  // f(x) = floor(Ax / B) - A * floor(x / B)
  // f(x + B) = floor(Ax/B + A) - A * floor(x/B + 1) = A + floor(Ax / B) - A - A
  // * floor(x / B) -> f(x) = floor(Ax / B) - A * floor(x / B) = f(x) よって、0
  // <= x <= B - 1 区間のみを考えればよい。 上記の場合、floor(Ax /
  // B)の最大値を求めればよいので、xの最大値を求めていく N < B - 1　-> x == N B
  // - 1 <= N -> x == B - 1

  int64_t ans = 0;

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

  cout << ans << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

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

  int64_t maxValue = 0;
  for (int x = 0; x <= N; x++) {
    int64_t value = (A * x) / B - A * (x / B);
    maxValue = max(maxValue, value);
  }

  cout << maxValue << endl;

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

#include <algorithm>
#include <cmath>
#include <iostream>
#include <queue>
#include <stdio.h>
#include <string>
#include <vector>

#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

/* a と b の最大公約数を返す関数 */
long long GCD(long long a, long long b) {
  if (b == 0)
    return a;
  else
    return GCD(b, a % b);
}

int main() {
  int a;
  ll b, n;
  ll x;

  cin >> a >> b >> n;
  x = min(n, b - 1);
  ll max = floor(a * x / b) - a * floor(x / b);

  cout << max << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <queue>
#include <stdio.h>
#include <string>
#include <vector>

#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

/* a と b の最大公約数を返す関数 */
long long GCD(long long a, long long b) {
  if (b == 0)
    return a;
  else
    return GCD(b, a % b);
}

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

  cin >> a >> b >> n;
  ll v_max = 0;

  int cnt = 0;
  for (ll x = n; x > 0; --x) {
    ll now;
    now = floor((a * x) / b) - a * floor(x / b);
    v_max = max(v_max, now);
    cnt++;

    if (cnt > 1e10) {
      break;
    }
  }

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

#include "bits/stdc++.h"
#include "math.h"

using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef vector<pair<ll, ll>> vp;
#define rep(i, a, b) for (ll i = (a); i < (b); ++i)
#define drep(i, a, b) for (ll i = (a); i > (b); --i)
const int MOD = 1000000007;
const int MAX = 510000;

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


Error: TLE

Fixed submission:

#include "bits/stdc++.h"
#include "math.h"

using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef vector<pair<ll, ll>> vp;
#define rep(i, a, b) for (ll i = (a); i < (b); ++i)
#define drep(i, a, b) for (ll i = (a); i > (b); --i)
const int MOD = 1000000007;
const int MAX = 510000;

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

#include "bits/stdc++.h"
#include "math.h"

using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef pair<ll, ll> P;
typedef vector<P> vp;
#define rep(i, a, b) for (ll i = (a); i < (b); ++i)
#define drep(i, a, b) for (ll i = (a); i >= (b); --i)
#define SIZE(a) int((a).size())
#define out(a) cout << (a) << endl;
const int INF = INT_MAX;
const int MAX = 510000;
const ll MOD = 1L << 32;
ll fac[MAX], finv[MAX], inv[MAX];

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

  cout << ans << endl;
}


Error: TLE

Fixed submission:

#include "bits/stdc++.h"
#include "math.h"

using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef pair<ll, ll> P;
typedef vector<P> vp;
#define rep(i, a, b) for (ll i = (a); i < (b); ++i)
#define drep(i, a, b) for (ll i = (a); i >= (b); --i)
#define SIZE(a) int((a).size())
#define out(a) cout << (a) << endl;
const int INF = INT_MAX;
const int MAX = 510000;
const ll MOD = 1L << 32;
ll fac[MAX], finv[MAX], inv[MAX];

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

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

#include <bits/stdc++.h>
using namespace std;
long long a, b, n, x;
int main() {
  cin >> a >> b >> n;
  if (n >= b) {
    x = b - 1;
    cout << a * x / b << endl;
  } else {
    x = n;
    cout << a * x / b << endl;
  }
}


Error: TLE

Fixed submission:

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

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


Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  long long a, b, n, max = 0, num = 0, i;
  cin >> a >> b >> n;
  for (i = 0; i <= n; i++) {
    num = (a * i) / b - a * (i / b);
    if (num > max) {
      max = num;
    }
  }
  cout << max << endl;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define rep(i, c) for (long long i = 0; i < (long long)c; i++)
int main() {
  long long a, b, n;
  cin >> a >> b >> n;
  long long ans = 0;
  long long t;
  /*	rep(x,n+1){
                  t=floor(a*x/b)-a*floor(x/b);
                  ans = max(t,ans);
          }
  */
  t = min(n, b - 1);
  ans = floor(a * t / b);
  cout << ans << endl;
  return 0;
}


Error: TLE

Fixed submission:

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

#include <iostream>
#include <vector>

using namespace std;

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

  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
#include <vector>

using namespace std;

int main() {
  long long a, b, n, max;
  cin >> a >> b >> n;
  max = a / b - (1 / b) * a;
  for (long long i = 2; i <= n; i++) {
    if (((a * i) / b - (i / b) * a) > max) {
      max = (a * i) / b - (i / b) * a;
    }
  }
  cout << max << endl;

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

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <utility>
#include <vector>

using namespace std;
long long abs(long long x, long long y) {
  long long tmp;
  if (y > x) {
    tmp = y;
    y = x;
    x = tmp;
  }
  return (x - y);
}

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

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


Error: TLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <utility>
#include <vector>

using namespace std;
long long abs(long long x, long long y) {
  long long tmp;
  if (y > x) {
    tmp = y;
    y = x;
    x = tmp;
  }
  return (x - y);
}

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

  long long ans1, ans2 = 0;
  int i = 1;
  while (i <= n && i <= b) {
    ans1 = a * i / b - a * (i / b);
    if (ans2 > ans1) {
      cout << ans2 << endl;
      return 0;
    } else {
      ans2 = max(ans2, ans1);
      i++;
    }
  }
  cout << ans2 << endl;
  return 0;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  // freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);

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

  long long int m = min(B - 1, N);
  cout << (A * m) / B - A * (m / B);

  return 0;
}


Error: TLE

Fixed submission:

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

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  // freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);

  long long int A, B, x;
  cin >> A >> B >> x;
  long long int ans = 0;
  // ans = max(ans, (A*x)/B - A*(x/B));
  // if (B<=1000000){
  //     for (int i=1; i<=A; i++){
  //         ans = max(ans, (A*x)/B - A*(x/B));
  //     }
  //     cout<<ans;
  // }
  // else{
  for (int i = B; i <= B + x && i < 100000000000; i++) {
    ans = max(ans, (A * i) / B - A * (i / B));
  }
  cout << ans;
  // }

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

// 失敗するからこそ
// そこから立ち向かって行く強さがあってそんな強さが本当の強さだと私は思うから
#ifdef DAIJOBU
#include "/home/v-o_o-v/deb.h"
#define deb(x...)                                                              \\
  cerr << "[" << #x << "] = [";                                                \\
  _print(x)
#else
#include <bits/stdc++.h>
#define deb(x...)
#endif

using namespace std;

#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n)-1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef long long lint;
typedef double ld;

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

  lint a, b, n;
  cin >> a >> b >> n;
  // lint ans = 0;
  lint ans = (a * (min(b - 1, n))) / b - a * ((min(b - 1, n)) / b);
  // for(int i = 1; i <= n; i++){
  // 	lint now = (a * i) / b - a * (i / b);
  // 	deb(now);
  // 	ans = max(ans, now);
  // }
  cout << ans;
  return 0;
}
// Write Here


Error: TLE

Fixed submission:

// 失敗するからこそ
// そこから立ち向かって行く強さがあってそんな強さが本当の強さだと私は思うから
#ifdef DAIJOBU
#include "/home/v-o_o-v/deb.h"
#define deb(x...)                                                              \\
  cerr << "[" << #x << "] = [";                                                \\
  _print(x)
#else
#include <bits/stdc++.h>
#define deb(x...)
#endif

using namespace std;

#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n)-1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef long long lint;
typedef double ld;

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

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

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define lson node << 1, st, mid
#define rson node << 1 | 1, mid + 1, ed
#define mem(a, x) memset(a, x, sizeof(a))
#define me(a) memset(a, 0, sizeof(a))
#define IOS ios::sync_with_stdio(false)
#define lowbit(x) x & (-x)
#define up(i, x, y) for (long long i = x; i < y; i++)
#define down(i, x, y) for (long long i = x; i >= y; i--)
#define in freopen("in.txt", "r", stdin)
#define out freopen("out.txt", "w", stdout)
typedef long long ll;
const ll mod = 1e9 + 7;
const ll INF = 0x3f3f3f3f;
const ll maxn = 1e6 + 5;
const ll N = 1e3 + 5;
const double pi = acos(-1.0);
const double eps = 1e-9;
using namespace std;

int main() {
  // in;
  // out;
  ll a, b, n;
  cin >> a >> b >> n;
  ll x;
  if (b - 1 <= n)
    x = (ll)floor((b - 1) * a * 1.0 / b) - a * floor((b - 1) * 1.0 / b);
  else
    x = (ll)floor(n * a * 1.0 / b) - a * floor(n * 1.0 / b);
  cout << x << endl;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define lson node << 1, st, mid
#define rson node << 1 | 1, mid + 1, ed
#define mem(a, x) memset(a, x, sizeof(a))
#define me(a) memset(a, 0, sizeof(a))
#define IOS ios::sync_with_stdio(false)
#define lowbit(x) x & (-x)
#define up(i, x, y) for (long long i = x; i < y; i++)
#define down(i, x, y) for (long long i = x; i >= y; i--)
#define in freopen("in.txt", "r", stdin)
#define out freopen("out.txt", "w", stdout)
typedef long long ll;
const ll mod = 1e9 + 7;
const ll INF = 0x3f3f3f3f;
const ll maxn = 1e6 + 5;
const ll N = 1e3 + 5;
const double pi = acos(-1.0);
const double eps = 1e-9;
using namespace std;

int main() {
  // in;
  // out;
  ll a, b, n;
  cin >> a >> b >> n;
  ll x, y;
  x = (ll)floor(n * a * 1.0 / b) - a * floor(n * 1.0 / b);
  y = (ll)floor((n - 1) * a * 1.0 / b) - a * floor((n - 1) * 1.0 / b);
  ll res = max(x, y);
  ll cnt = -100;
  if (n <= 1000000001)
    cout << res << endl;
  else {
    for (int i = 2; i <= 1000000000; i++) {
      ll z = floor((n - i) * a * 1.0 / b) - a * floor((n - i) * 1.0 / b);
      cnt = max(cnt, z);
    }
    for (int i = 1; i <= 1000000000; i++) {
      ll z = floor(i * a * 1.0 / b) - a * floor(i * 1.0 / b);
      cnt = max(cnt, z);
    }
    cout << max(res, cnt) << endl;
  }
}
Problem p02696 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using ll = long long;
using namespace std;

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

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

Error: 0

Fixed submission:

#include <bits/stdc++.h>

using ll = long long;
using namespace std;

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

  vector<long double> ans(n, 0);

  for (int i = 1; i <= n; i++)
    ans[i - 1] = floor(a * i / b) - a * floor(i / b);

  sort(ans.begin(), ans.end());

  cout << floor(ans[n - 1]) << endl;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

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

#define E "\\n"
#define int long long
#define f(i, l, n) for (int i = l; i < n; i++)

int32_t main() {

  int a, b, n;
  cin >> a >> b >> n;
  int ans = INT_MIN;
  if (b == 1)
    return cout << 0, 0;

  for (int i = 1; i <= n / b; i++) {
    int x = i * b - 1;
    ans = max(ans, (a * x) / b - a * (x / b));
  }
  if (n < b)
    ans = (a * n) / b - a * (n / b);
  cout << ans;
}

Error: TLE

Fixed submission:

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

#define E "\\n"
#define int long long
#define f(i, l, n) for (int i = l; i < n; i++)

int32_t main() {

  int a, b, n;
  cin >> a >> b >> n;
  int ans = INT_MIN;

  for (int i = 1; i <= n / b; i++) {
    int x = i * b - 1;

    ans = max(ans, (a * x) / b - a * (x / b));
  }
  if (n < b)
    ans = (a * n) / b - a * (n / b);
  cout << ans;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

#define pb push_back
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n, s) for (int i = (s); i < (n); i++)
#define rrep(i, n) for (int i = (n - 1); i >= 0; i--)
#define rreps(i, n, s) for (int i = s; i >= n; i--)
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;
}

using ll = long long;
using namespace std;
constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int MOD = 1000000007;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll a, b, n;
  cin >> a >> b >> n;
  auto f = [&](ll x) { return (ll)floor(a * x / (double)b); };

  ll ans = f(min(b - 1, n));
  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

#define pb push_back
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n, s) for (int i = (s); i < (n); i++)
#define rrep(i, n) for (int i = (n - 1); i >= 0; i--)
#define rreps(i, n, s) for (int i = s; i >= n; i--)
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;
}

using ll = long long;
using namespace std;
constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int MOD = 1000000007;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll a, b, n;
  cin >> a >> b >> n;
  ll max_val = -1;
  rep(x, n + 1) {
    ll val = floor(a * x / b) - a * floor(x / b);
    chmax(max_val, val);
  }
  cout << max_val << 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, score = 0;
  cin >> a >> b >> n;
  /*
  for(int i=1; i<=min(b,n); i++){
      //cout<<">"<<a*i/b-a*(i/b)<<endl;
      score=max(a*i/b-a*(i/b),score);
  }
  */
  ll x = min(n, b - 1);
  cout << a * x / b - a * (x / b) << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

typedef long long ll;
int main() {
  ll a, b, n, score = 0;
  cin >> a >> b >> n;
  for (int i = 1; i <= min(b, n); i++) {
    // cout<<">"<<a*i/b-a*(i/b)<<endl;
    score = max(a * i / b - a * (i / b), score);
  }
  cout << score << endl;
  return 0;
}