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

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

int main(void) {
  long long a, b, n, i;
  cin >> a >> b >> n;
  int max = floor(a * n / b) - a * floor(n / b);
  int k = n / b;
  for (i = b * k - 1; i >= 0; i -= b) {
    int f = floor(a * i / b) - a * floor(i / b);
    if (max < f) {
      max = f;
    }
  }
  cout << max << endl;
  return 0;
}

Error: TLE

Fixed submission:

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

int main(void) {
  unsigned long long a, b, n, i;
  cin >> a >> b >> n;
  int max = 0;
  for (i = 0; i <= n; i++) {
    int f = floor(a * i / b) - a * floor(i / b);
    if (max < f) {
      max = f;
    }
  }
  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;

  long long x = n < b - 1 ? n : b - 1;
  cout << (a * x) / b - a * (x / b);

  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 max = 0;
  for (long long x = 1; x <= n; x++) {
    long long v = ((a * x) / b) - (a * (x / b));
    if (v > max) {
      max = v;
    }
  }

  cout << max;

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

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rep1(i, n) for (int i = 1; i <= n; ++i)
#define co(x) cout << (x) << "\\n"
#define cosp(x) cout << (x) << " "
int main() {
  ll a, b, n;
  cin >> a >> b >> n;
  ll x = min(n, b - 1);
  co(a * x / b - a * (x / b));
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rep1(i, n) for (int i = 1; i <= n; ++i)
#define co(x) cout << (x) << "\\n"
#define cosp(x) cout << (x) << " "

int main() {
  double a, b, n;
  cin >> a >> b >> n;
  int mn = -1;
  for (int i = min(n, b - 1); i <= n;) {
    int k = floor(a * i / b) - (int)a * floor(i / b);
    if (mn < k)
      mn = k;
    i += b;
  }
  co(mn);
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
using ll = long long int;
using dd = long double;
const ll MOD = 1e9 + 7;
const dd PI = 3.1415926535;

class UnionFind {
  std::vector<int> p;

public:
  UnionFind(int n) : p(n, -1) {}

  int root(int x) { return p[x] < 0 ? x : p[x] = root(p[x]); }

  bool same(int x, int y) { return root(x) == root(y); }

  bool unite(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y)
      return false;
    if (p[y] < p[x])
      std::swap(x, y);
    if (p[x] == p[y])
      --p[x];
    p[y] = x;
    return true;
  }
};

ll fast(ll n, ll k) {
  if (k == 0) {
    return 1;
  }
  if (k == 1) {
    return n;
  }
  if (k % 2 == 0) {
    ll tmp = fast(n, k / 2);
    return tmp * tmp % MOD;
  } else {
    ll tmp = fast(n, k / 2);
    tmp = tmp * tmp % MOD;
    return n * tmp % MOD;
  }
}

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

  cout << floor(A * min(B - 1.0, N) / B) << endl;
}

Error: TLE

Fixed submission:

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

using namespace std;
using ll = long long int;
using dd = long double;
const ll MOD = 1e9 + 7;
const dd PI = 3.1415926535;

ll fast(ll n, ll k) {
  if (k == 0) {
    return 1;
  }
  if (k == 1) {
    return n;
  }
  if (k % 2 == 0) {
    ll tmp = fast(n, k / 2);
    return tmp * tmp % MOD;
  } else {
    ll tmp = fast(n, k / 2);
    tmp = tmp * tmp % MOD;
    return n * tmp % MOD;
  }
}

int main() {
  dd A, B, N;
  cin >> A >> B >> N;
  bool ok = false;

  ll ans = (floor(A * (dd)((dd)N / (dd)B)) - A * floor((dd)((dd)N / (dd)B)));

  for (ll i = N; i >= max((ll)(N - B), 0LL); i--) {
    ans = max(ans, (ll)(floor(A * (dd)(i / B)) - A * floor((dd)(i / B))));
  }

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


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

void Main() {
  // input
  u_int64_t A, B, N;
  cin >> A >> B >> N;

  // translate
  u_int64_t ans = 0;
  if (B == 1) {
    cout << 0 << endl;
    return;
  }

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

  for (u_int64_t x = B - 1; x <= N; x += B) {
    u_int64_t num = (A * x) / B - A * (x / B);
    ans = max(ans, num);
  }

  // output
  cout << ans << endl;
}

int main() {
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}


Error: TLE

Fixed submission:


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

void Main() {
  // input
  u_int64_t A, B, N;
  cin >> A >> B >> N;

  // translate
  u_int64_t ans = 0;
  if (N < B) {
    cout << (A * N) / B << endl;
    return;
  }

  for (u_int64_t x = B - 1; x <= N; x += B) {
    u_int64_t num = (A * x) / B - A * (x / B);
    ans = max(ans, num);
  }

  // output
  cout << ans << endl;
}

int main() {
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bits/stdc++.h> // isupper, islower, isdigit, toupper, tolower
#include <bitset>        // bitset
#include <cmath>         // sqrt
#include <cstdint>       // int64_t, int*_t
#include <cstdio>        // printf
#include <deque>         // deque
#include <iostream>      // cout, endl, cin
#include <map>           // map
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <string>        // string, to_string, stoi
#include <tuple>         // tuple, make_tuple
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <utility>       // pair, make_pair
#include <vector>        // vector
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, n) for (int i = (a); i < (n); i++)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> Pl;
typedef pair<int, int> P;
typedef tuple<ll, ll, string> Tlls;

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

  ans = max(ans, tmp);

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


Error: TLE

Fixed submission:

#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bits/stdc++.h> // isupper, islower, isdigit, toupper, tolower
#include <bitset>        // bitset
#include <cmath>         // sqrt
#include <cstdint>       // int64_t, int*_t
#include <cstdio>        // printf
#include <deque>         // deque
#include <iostream>      // cout, endl, cin
#include <map>           // map
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <string>        // string, to_string, stoi
#include <tuple>         // tuple, make_tuple
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <utility>       // pair, make_pair
#include <vector>        // vector
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, n) for (int i = (a); i < (n); i++)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> Pl;
typedef pair<int, int> P;
typedef tuple<ll, ll, string> Tlls;

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

#include <cmath>
#include <iostream>
using namespace std;
typedef long long ll;
int main() {
  ll a, b, n, x;
  cin >> a >> b >> n;
  if (n >= b)
    x = b - 1;
  else
    x = n;

  ll sum = (a * x / b) - a * (x / b);
  cout << sum;
}

Error: TLE

Fixed submission:

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

#include <array>
#include <iostream>
#include <map>
#include <math.h>
#include <string>

using namespace std;

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

  long int max_value = 0;
  max_value = std::floor(a * n / b) - a * std::floor(n / b);

  if (n >= b) {

    long int i = b - 1;
    long int value = std::floor(a * i / b) - a * std::floor(i / b);
    max_value = max(max_value, value);
  }

  cout << max_value << endl;
}

Error: TLE

Fixed submission:

#include <array>
#include <iostream>
#include <map>
#include <string>

using namespace std;

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

  int max_value = 0;
  max_value = (a * n / b) - a * (n / b);
  if (n >= b) {
    int i = b - 1;
    while (i < n) {
      int value = (a * i / b) - a * (i / b);
      max_value = max(max_value, value);

      i += b;
    }
  }

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

#include <bits/stdc++.h>
#define ll long long int
#define ul unsigned long long int
#define va vector<long long int> a
#define vb vector<long long int> b
#define M 1000000007
using namespace std;
ll t;
void fast() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(0);
}
ll power(ll x, ul y, ll p) {
  ll res = 1;
  x = x % p;
  if (x == 0)
    return 0;
  while (y > 0) {
    if (y & 1)
      res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
void solve() {
  double a, b, n;
  cin >> a >> b >> n;
  ll max1 = min(b - 1, n);
  // for(double i=n;i>=0;i--){
  ll m1 = (ll)(floor((a * (max1)) / b)) - a * floor((max1) / b);
  //}
  cout << m1;
}
int main() {
  fast();
  solve();
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define ll long long int
#define ul unsigned long long int
#define va vector<long long int> a
#define vb vector<long long int> b
#define M 1000000007
using namespace std;
ll t;
void fast() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(0);
}
ll power(ll x, ul y, ll p) {
  ll res = 1;
  x = x % p;
  if (x == 0)
    return 0;
  while (y > 0) {
    if (y & 1)
      res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
void solve() {
  double a, b, n;
  cin >> a >> b >> n;
  double max1 = INT_MIN;
  for (double i = n; i >= 0; i--) {
    max1 = max(max1, (ll)(floor((a * i) / b)) - a * floor(i / b));
  }
  cout << max1;
}
int main() {
  fast();
  solve();
  return 0;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
// 型に気を付けよう

#define rep(i, n) for (i = 1; i < n; i++)
typedef long long ll;
typedef long double ld;
const double pi = 3.1415926535;
const ll mod = 1000000007;
// 桁数指定　cout << fixed << setprecision(2)
int main() {
  ld ans = 0;
  ld a, b, n;
  cin >> a >> b >> n;
  ll x = min(b - 1, n);
  ld sum = floorl(a * x / b) - a * floorl(x / b);
  ans = max(ans, sum);
  cerr << x << sum << endl;

  cout << ans;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
// 型に気を付けよう

#define rep(i, n) for (i = 1; i < n; i++)
typedef long long ll;
typedef long double ld;
const double pi = 3.1415926535;
const ll mod = 1000000007;
// 桁数指定　cout << fixed << setprecision(2)
int main() {
  ld ans = 0;
  ld a, b, n;
  cin >> a >> b >> n;
  int x = 1;
  rep(x, min(b, n + 1)) {
    ld sum = floorl(a * x / b) - a * floorl(x / b);
    ans = max(ans, sum);
    // cerr<<x<<sum<<endl;
  }
  cout << ans;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
typedef long long ll;
using namespace std;

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

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
typedef long long ll;
using namespace std;

int main() {
  int64_t a, b, n;
  cin >> a >> b >> n;
  int64_t m = 0;
  rep(i, n / 2, n + 1) { m = max(m, ((a * i / b) - a * (i / b))); }
  cout << m << endl;
}
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++)
typedef long long ll;
using namespace std;

int main() {
  ll a, b, n, ans = -1;

  cin >> a >> b >> n;
  ll x = n, cnt = 0;

  if (b <= n) {
    x = b;
    if (b != n)
      ans = max(ans, a * (x + 1) / b - a * ((x + 1) / b));
    ans = max(ans, a * (x - 1) / b - a * ((x - 1) / b));
  } else {
    ans = a * n / b - a * (n / b);
  }

  /*
  x = n;
  while (x) {
      cout << "x = " << x << " " << a * x / b - a * (x / b) << endl;
      ans = max(ans, a * x / b - a * (x / b));
      x--;
      if (cnt > 1e+7) break;
      cnt++;
  }
*/

  cout << ans << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

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

int main() {
  ll a, b, n, ans = -1;

  cin >> a >> b >> n;
  ll x = n, cnt = 0;

  while (x) {
    ans = max(ans, a * x / b - a * (x / b));
    x--;
    if (cnt > 1e+7)
      break;
  }

  cout << ans << endl;

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

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

ll a, b, n;

int main() {
  cin >> a >> b >> n;
  ll l = 0;
  ll r = n;
  ll maxx = floor((a * 1) / b) - a * floor(1 / b);
  ;
  while (r >= l) {
    ll mid = (l + r) / 2;
    ll x = mid;
    ll res = floor((a * x) / b) - a * floor(x / b);
    // cout << mid << endl;
    if (res < maxx) {
      r = mid;
    } else {
      l = mid + 1;
    }
    maxx = max(maxx, res);
    if (l == r) {
      x = l;
      res = floor((a * x) / b) - a * floor(x / b);
      maxx = max(maxx, res);
      break;
    }
  }
  cout << maxx << endl;
  return 0;
}


Error: TLE

Fixed submission:

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

ll a, b, n;

int main() {
  cin >> a >> b >> n;
  ll l = 0;
  ll r = n;
  ll maxx = floor((a * 1) / b) - a * floor(1 / b);
  ;
  while (r >= l) {
    ll mid = (l + r) / 2;
    ll x = mid;
    ll res = floor((a * x) / b) - a * floor(x / b);
    if (res < maxx) {
      r = mid;
    } else {
      l = mid + 1;
    }
    maxx = max(maxx, res);
  }
  cout << maxx << endl;
  return 0;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

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

typedef long long ll;
typedef int64_t i6;

#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep2(i, n) for (ll i = 1; i <= n; ++i)
#define ALL(v) (v).begin(), (v).end()
#define Sort(x) sort(ALL(x))
#define Sort_rev(x)                                                            \\
  Sort(x);                                                                     \\
  reverse(ALL(x))

template <typename V, typename T> T find_num(V v, T num) {
  if (find(ALL(v), num) == v.end()) {
    return false;
  } else {
    return true;
  }
}

// π M_PI
// deg = rad*180/M_PI

ll num(ll a, ll b, ll i) {
  ll ans = (int)(a * i / b) - a * (int)(i / b);
  // cout << "a " << ans << endl;
  return ans;
}

int main() {
  ll a, b, n;
  cin >> a >> b >> n;
  ll ans = 0;
  if (n < b) {
    std::vector<ll> v;
    /*
    rep2(i, n) {
        v.push_back( num(a, b, i) );
    }
    ans = *max_element(ALL(v));*/
    ans = num(a, b, n);
  } else {
    ll nn = b;
    ll i = 2;
    // std::vector<ll> v;
    priority_queue<ll> q;
    while (nn <= n) {
      // v.push_back( num(a, b, nn-1) );
      // v.push_back( num(a, b, nn) );
      ll k = num(a, b, nn - 1);
      if (!q.empty() && k < q.top()) {
        break;
      }
      q.push(num(a, b, nn - 1));
      q.push(num(a, b, nn));
      nn = b * i;
      i++;
    }
    ans = q.top();
  }

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


Error: TLE

Fixed submission:

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

typedef long long ll;
typedef int64_t i6;

#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep2(i, n) for (ll i = 1; i <= n; ++i)
#define ALL(v) (v).begin(), (v).end()
#define Sort(x) sort(ALL(x))
#define Sort_rev(x)                                                            \\
  Sort(x);                                                                     \\
  reverse(ALL(x))

template <typename V, typename T> T find_num(V v, T num) {
  if (find(ALL(v), num) == v.end()) {
    return false;
  } else {
    return true;
  }
}

// π M_PI
// deg = rad*180/M_PI

ll num(ll a, ll b, ll i) {
  ll ans = (int)(a * i / b) - a * (int)(i / b);
  // cout << "a " << ans << endl;
  return ans;
}

int main() {
  ll a, b, n;
  cin >> a >> b >> n;
  ll ans = 0;
  if (n < b) {
    std::vector<ll> v;
    /*
    rep2(i, n) {
        v.push_back( num(a, b, i) );
    }
    ans = *max_element(ALL(v));*/
    ans = num(a, b, n);
  } else {
    ll nn = b;
    ll i = 2;
    // std::vector<ll> v;
    priority_queue<ll> q;
    while (nn <= n) {
      // v.push_back( num(a, b, nn-1) );
      // v.push_back( num(a, b, nn) );
      ll k = num(a, b, nn - 1); /*
         if ( !q.empty() && k < q.top() ) {
             break;
         }*/
      q.push(num(a, b, nn - 1));
      q.push(num(a, b, nn));
      nn = b * i;
      i++;
    }
    ans = q.top();
  }

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

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

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

Error: 0

Fixed submission:

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

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

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

int main() {
  long long A, B, N, num;
  cin >> A >> B >> N;
  if (N < B) {
    num = N;
  } else if (N % B == B - 1) {
    num = N;
  } else {
    num = N / B * B - 1;
  }
  cout << A * num / B - A * (num / B);
}

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 = A / B - A * (1 / B);
  for (int i = 1; i <= N; i++) {
    if (A * i / B - A * (i / B) > ans) {
      ans = A * i / B - A * (i / B);
    }
  }
  cout << ans;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define _Max(a, b, c) Max(a, Max(b, c))
#define lop(i, a, b) for (int i = a; i < b; i++)
#define pb push_back
using namespace std;
/*
 *
 * Saroar Zahan Sojib
 * Green University - Bangladesh (GUB)
 *
 */
int main() {
  long long A, B, N;
  cin >> A >> B >> N;
  long long x = min(B - 1, N);
  cout << (A * x) / B - A * (x / B) << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define _Max(a, b, c) Max(a, Max(b, c))
#define lop(i, a, b) for (int i = a; i < b; i++)
#define pb push_back
using namespace std;
/*
 *
 * Saroar Zahan Sojib
 * Green University - Bangladesh (GUB)
 *
 */
int main() {
  set<long long> vec;
  long long a, b, n, i, k;
  cin >> a >> b >> n;
  k = sqrt(n);
  for (i = k; i <= n; i++) {
    long long e, f, g;
    e = floor((a * i) / b);
    f = floor(i / b);
    g = e - (a * f);
    vec.insert(g);
  }
  long long max = 0;
  for (auto x : vec) {
    if (max < x) {
      max = x;
    }
  }
  cout << max << endl;
  return 0;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define eb emplace_back
#define precision(n) cout << fixed << setprecision(n);
#define fast                                                                   \\
  {                                                                            \\
    ios_base::sync_with_stdio(false);                                          \\
    cin.tie(NULL);                                                             \\
  }
int main() {
  fast;
  long long int n, a, b;
  long long int ans;
  cin >> a >> b >> n;
  if (b > n) {
    ans = n;
  } else {
    ans = b - 1;
  }

  cout << (ans * a) / b - a * (ans / b) << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define eb emplace_back
#define precision(n) cout << fixed << setprecision(n);
#define fast                                                                   \\
  {                                                                            \\
    ios_base::sync_with_stdio(false);                                          \\
    cin.tie(NULL);                                                             \\
  }
int main() {
  fast;
  long long int n, a, b, p, x;
  long long int ans = 0;
  cin >> a >> b >> n;
  for (long long int i = 1; i <= n; i++) {
    p = ((a * i) / b) - (a * (i / b));
    ans = max(ans, p);
  }
  cout << ans << endl;
  // cout<<p<<endl;
  return 0;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;

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

  long int ans;
  long double x;

  cin >> a >> b >> n;

  ans = int(a * min(n, b - 1) / b) - a * int(min(n, b - 1) / b);

  /*
  for(double i = b<n?b:n; i >0; i--) {
      ans = int(a*i/b)-a*int(i/b);
      if(max < ans){
          max=ans;
      }
  }
  */

  cout << ans << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

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

  long int ans;
  long int x;

  cin >> a >> b >> n;

  int max = 0;
  for (double i = b < n ? b : n; i > 0; i--) {
    ans = int(a * i / b) - a * int(i / b);
    if (max < ans) {
      max = ans;
    }
  }

  cout << max << endl;

  return 0;
}