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

#ifdef DEBUG

#else

#pragma GCC optimize("O3,no-stack-protector")
#pragma GCC optimize("unroll-loops")

#if __cplusplus >= 201703L
#pragma GCC target("avx2")
#else
#pragma GCC target("avx")
#endif

#endif
// 実数の場合
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
typedef int64_t Int;
typedef long double Ld;

using namespace std;
using Graph = vector<vector<Int>>;

const double pi = M_PI;
const Int MOD = 1000000007;

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

  Int a, b, n;
  cin >> a >> b >> n;

  Int x;
  if (n < b - 1) {
    x = n;
  } else {
    x = b - 1;
  }
  Int ans = (a * x / b) - a * (x / b);

  cout << ans << endl;

  return 0;
}


Error: TLE

Fixed submission:

#ifdef DEBUG

#else

#pragma GCC optimize("O3,no-stack-protector")
#pragma GCC optimize("unroll-loops")

#if __cplusplus >= 201703L
#pragma GCC target("avx2")
#else
#pragma GCC target("avx")
#endif

#endif
// 実数の場合
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
typedef int64_t Int;
typedef long double Ld;

using namespace std;
using Graph = vector<vector<Int>>;

const double pi = M_PI;
const Int MOD = 1000000007;

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

  Int a, b, n;
  cin >> a >> b >> n;

  Int ans = INT64_MIN, now = 0;
  bool first = true;
  for (Int i = 1; i <= n; i++) {
    now = ((a * i / b) - a * (i / b));
    ans = max(ans, now);

    if (first) {
      if (now != 0) {
        first = false;
      }
    } else {
      if (now == 0) {
        break;
      }
    }
  }

  cout << ans << endl;

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

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

int main() {
  int A;
  long long int B, N;
  cin >> A >> B >> N;
  if (N >= B) {
    cout << floor((A * B - A - B) / B) + 1 << endl;
  } else {
    int f = floor(A * N / B);
    cout << f << endl;
  }
}

Error: TLE

Fixed submission:

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

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

#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>    // bitset
#include <cctype>    // isupper, islower, isdigit, toupper, tolower
#include <cstdint>   // int64_t, int*_t
#include <cstdio>    // printf
#include <deque>     // deque
#include <iomanip>   // fixed, setprecision
#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
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

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


Error: TLE

Fixed submission:

#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>    // bitset
#include <cctype>    // isupper, islower, isdigit, toupper, tolower
#include <cstdint>   // int64_t, int*_t
#include <cstdio>    // printf
#include <deque>     // deque
#include <iomanip>   // fixed, setprecision
#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
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

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

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

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

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

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


Error: TLE

Fixed submission:

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

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

  bool flag = false;
  long long ans = 0;
  long long tmp;
  for (int x = 0; x <= N; x++) {
    if (A * x < B)
      continue;
    else if (x < B)
      tmp = (A * x) / B;
    else
      tmp = (A * x) / B - A * (x / B);
    if (tmp > ans) {
      ans = tmp;
      flag = true;
    }
    if (flag == true && tmp == 0)
      goto END;
  }
END:
  cout << ans << 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++)
#define all(v) v.begin(), v.end()
#define _GLIBCXX_DEBUG

long long f(long long a, long long b, long long x) {
  return a * x / b - a * (x / b);
}

int main() {
  using vi = vector<int>;

  long long a, b, n;
  cin >> a >> b >> n;
  long long x = 0;
  long long re = f(a, b, x);
  // int g = gcd(a,b);
  x += b;
  if (x > n) {
    x = n + 1;
  }
  long long y = f(a, b, x - 1);
  if (y > re) {
    re = y;
  }
  cout << re << endl;
}

Error: TLE

Fixed submission:

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

long long f(long long a, long long b, long long x) {
  return a * x / b - a * (x / b);
}

int main() {
  using vi = vector<int>;

  long long a, b, n;
  cin >> a >> b >> n;
  long long x = 0;
  long long re = f(a, b, x);
  // int g = gcd(a,b);
  while (x <= n) {
    x += b;
    if (x > n) {
      x = n + 1;
    }
    long long y = f(a, b, x - 1);
    if (y > re) {
      re = y;
    }
  }
  cout << re << endl;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <map>
#include <math.h>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;
long long a, b, n;
long long int dfs(long long int k) { return a * k / b - a * (k / b); }
int main() {
  long long int i;
  cin >> a >> b >> n;
  if (b - 1 <= n) {
    printf("%lld\\n", dfs(b - 1));
  } else {
    printf("%lld\\n", dfs(n));
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <map>
#include <math.h>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;
long long a, b, n;
long long int dfs(long long int k) { return a * k / b - a * (k / b); }
int main() {
  long long int i;
  cin >> a >> b >> n;
  for (i = 0; i <= n; i++) {
    if (dfs(i) > dfs(i + 1)) {
      printf("%lld\\n", dfs(i));
      return 0;
    }
  }
  printf("%lld\\n", dfs(n));
  return 0;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define SORT(a) sort((a).begin(), (a).end())
#define RSORT(a) reverse((a).begin(), (a).end())
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
const long long INF = 1LL << 60;
// const int INF=1010101010;
using Graph = vector<vector<int>>;

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

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define SORT(a) sort((a).begin(), (a).end())
#define RSORT(a) reverse((a).begin(), (a).end())
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
const long long INF = 1LL << 60;
// const int INF=1010101010;
using Graph = vector<vector<int>>;

int main() {
  ll a, b, n;
  cin >> a >> b >> n;
  ll ma = 0;
  for (int x = 0; x <= min(b, n); x++) {
    ma = max(a * x / b - x / b * a, ma);
    if (a * x / b - x / b * a >= a)
      break;
  }

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

#include <algorithm>
#include <cmath>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
long long MOD = 1000000007LL;
const double PI = 3.14159265358979323846;
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483648
#define INT_MAX 2147483647
#define endl "\\n"

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

  long long ans = 0;
  long long x = min(N, B - 1);
  ans = floor((A * x) / B);

  cout << ans << endl;

  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
long long MOD = 1000000007LL;
const double PI = 3.14159265358979323846;
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483648
#define INT_MAX 2147483647
#define endl "\\n"

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

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

  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 < (int)(n); i++)
#define put(i) cout << fixed << i << endl
using namespace std;
using ll = long long;

// pdf見て解答

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

  ll x = min(b - 1, n);
  put(a * x / b - (a * (x / b)));
}

Error: TLE

Fixed submission:

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

bool is_integer(double x) { return std::floor(x) == x; }

int main() {
  ll maxn = 0, cnt = 0;
  ll a, b, n;
  cin >> a >> b >> n;
  ll tmp, pre = 1e12;
  map<ll, ll> mp;

  for (ll i = n; i > 0; i--) {
    maxn = max(maxn, a * i / b - a * (i / b));
    mp[a * i / b - a * (i / b)]++;

    // cout << a * i / b - a * (i / b) << " " << i << endl;;
    tmp = a * i / b - a * (i / b);
    // put(tmp);
    if (tmp > pre) {
      break;
    }
    if (tmp == pre) {
      cnt++;
    }
    if (cnt > 1000000000) {
      break;
    }
    pre = tmp;
    // if(mp[a * i / b - a * (i / b)] > 5) break;
    // put(a * i / b - a * (i / b));
    /*
    ll cnt = 0;
    for(auto k : mp){
        if(k.second > 2) cnt++;
        else break;
    }
    if(cnt == mp.size()) break;*/
  }

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

#include <algorithm>
#include <cstdio>
using namespace std;

long long a, b, n, maxn, m;

int main(void) {
  scanf("%lld%lld%lld", &a, &b, &n);
  if (b - 1 <= n)
    maxn = a * (b - 1) / b - a * ((b - 1) / b);
  m = a * n / b - a * (n / b);
  maxn = max(maxn, m);

  printf("%lld", maxn);
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdio>
using namespace std;

long long a, b, n, maxn, m;

int main(void) {
  scanf("%lld%lld%lld", &a, &b, &n);
  for (int i = b - 1; i <= n; i++) {
    m = a * i / b - a * (i / b);
    maxn = max(maxn, m);
    i += b;
  }
  m = a * n / b - a * (n / b);
  maxn = max(maxn, m);

  printf("%lld", maxn);
  return 0;
}
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 target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define int long long

using namespace std;

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

int32_t main() {
  speed;
  int a, b, n;
  cin >> a >> b >> n;
  int mx = (a * n) / b - a * (n / b);
  for (int x = 1; x <= min(10000000ll, n); x++) {
    mx = max(mx, (a * x) / b - a * (x / b));
  }
  for (int x = n; x >= max(1ll, n - 10000000ll); x--) {
    mx = max(mx, (a * x) / b - a * (x / b));
  }
  int cnt = 0;
  for (int x = 10000001; x <= n; x += 1000) {
    mx = max(mx, (a * x) / b - a * (x / b));
    cnt++;
    if (cnt >= N) {
      break;
    }
  }
  cnt = 0;
  for (int x = max(1ll, n - N); x >= 1; x -= 1000) {
    mx = max(mx, (a * x) / b - a * (x / b));
    cnt++;
    if (cnt > N) {
      break;
    }
  }
  for (int x = 10000001; x <= n; x += 100000) {
    mx = max(mx, (a * x) / b - a * (x / b));
  }
  cout << mx;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define int long long int
using namespace std;
signed main() {
  int a, b, n;
  cin >> a >> b >> n;
  int maxi = INT_MIN;

  for (int x = 0; x <= n; x++) {
    int t = floor((a * x) / b) - a * floor(x / b);
    maxi = max(t, maxi);
  }
  cout << maxi;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <bits/stdc++.h>
#include <cstdlib>
#include <iostream>
#include <math.h>
#include <queue>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;

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

Error: TLE

Fixed submission:

#include <algorithm>
#include <bits/stdc++.h>
#include <cstdlib>
#include <iostream>
#include <math.h>
#include <queue>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;

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

Error: TLE

Fixed submission:

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

#define ll long long

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

#include <iostream>
using namespace std;
int main() {
  long long A, B, N, max = 0;
  cin >> A >> B >> N;

  long long x = 0;

  if (N >= B)
    x = B - 1;
  else
    x = N;

  long long res = (A * x) / B;

  cout << res << endl;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  long long A, B, N, max = 0;
  cin >> A >> B >> N;
  for (long long x = N; x >= 0; x -= 1) {
    long long Ax = A * x;
    long long res = Ax / B - A * (x / B);
    if (res > max)
      max = res;
  }
  cout << max << endl;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int a, b, n, i, a1, a2;
  cin >> a >> b >> n;
  i = n;
  while (i >= b) {
    i--;
  }
  a1 = ((a * i) / b);
  a2 = (i / b);
  cout << a1 - a * a2;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h> //author::@whohet-->Het Patel
#define fasterthanlight                                                        \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL)
#define test                                                                   \\
  int T;                                                                       \\
  cin >> T;                                                                    \\
  while (T--)
#define endl "\\n"
#define int long long
#define uint unsigned long long
#define ld long double
#define pii pair<int, int>
#define vi vector<int>
#define vc vector<char>
#define vs vector<string>
#define vvi vector<vector<int>>
#define mii map<int, int>
#define msi map<string, int>
#define mis map<int, string>
#define pb push_back
#define mod 1000000007
#define PI 3.141592653589793238

using namespace std;

// author::@whohet-->Het Patel

signed main() {
  fasterthanlight;
  int a, b, n;
  cin >> a >> b >> n;
  int max = -mod, i;
  int t = 0;
  for (int x = n; x >= sqrt(n); x--) {
    t++;
    if (max < ((a * x) / b) - (a * (x / b))) {
      max = ((a * x) / b) - (a * (x / b));
      i = x;
    }
    // if(n>=b)
    // x=(b*t)-1;
    // else x++;
  }
  cout << max;
}
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 (ll i = 0; i < n; i++)

const ll INF = 1001001001;

const double PI = 3.141592653;

const ll MOD = 1000000007; // 大きい素数

// 提出のときに言語がc＋＋似合っていることを確認する

// 絶対値の関数
int z(int a, int b) {
  if (a > b)
    return a - b;
  else
    return b - a;
}

int main() {
  ll a, b, n;
  cin >> a >> b >> n;
  ll l = min(n, b - 1);
  ll sum = (a * l) / b;
  cout << sum << endl;

  return 0;
}


Error: TLE

Fixed submission:

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

const ll INF = 1001001001;

const double PI = 3.141592653;

const ll MOD = 1000000007; // 大きい素数

// 提出のときに言語がc＋＋似合っていることを確認する

// 絶対値の関数
int z(int a, int b) {
  if (a > b)
    return a - b;
  else
    return b - a;
}

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

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

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

#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define repi(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define uniqueV(x)                                                             \\
  sort(x.begin(), x.end());                                                    \\
  x.erase(unique(x.begin(), x.end()), x.end());
#define debug(x) cerr << #x << ": " << x << '\\n'
#define debug2(x, y)                                                           \\
  cerr << "(" << #x << ", " << #y << ") = "                                    \\
       << "(" << x << ", " << y << ")" << '\\n'

typedef long long int ll;
typedef pair<int, int> P;

const long long INF = 3e18 + 12;
const int inf = 1e9;

// ----------------------------------------------

ll f(ll a, ll b, ll x) {
  return floorl(double(a * x / b)) - (a * floorl(double(x / b)));
}

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

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

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

Error: TLE

Fixed submission:

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

#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define repi(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define uniqueV(x)                                                             \\
  sort(x.begin(), x.end());                                                    \\
  x.erase(unique(x.begin(), x.end()), x.end());
#define debug(x) cerr << #x << ": " << x << '\\n'
#define debug2(x, y)                                                           \\
  cerr << "(" << #x << ", " << #y << ") = "                                    \\
       << "(" << x << ", " << y << ")" << '\\n'

typedef long long int ll;
typedef pair<int, int> P;

const long long INF = 3e18 + 12;
const int inf = 1e9;

// ----------------------------------------------

ll f(ll a, ll b, ll x) { return int((a * x) / b) - a * int(x / b); }

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

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

  int left = 1, right = n + 1;

  rep(i, 100000000) {
    double c1 = (left * 2 + right) / 3;
    double c2 = (left + right * 2) / 3;

    if (f(a, b, c1) < f(a, b, c2))
      left = c2;
    else
      right = c1;
  }
  cout << fixed << setprecision(20) << f(a, b, left) << endl;

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

#include <algorithm>
#include <cmath>
#include <iostream>
typedef long long ll;

using namespace std;

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

  if (b > n) {
    cout << floor((a * n) / b) << endl;
  } else if (b == 1) {
    cout << max << endl;
  } else {
    for (i = b - 1; i <= n; i += b) {
      if (max < (floor((a * i) / b) - a * floor(i / b)))
        max = floor((a * i) / b) - a * floor(i / b);
    }
    cout << max << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
typedef long long ll;

using namespace std;

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

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

#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <vector>
#define ll long long
#define MOD = 1e9 + 7

using namespace std;

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

Error: TLE

Fixed submission:

#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <vector>
#define ll long long
#define MOD = 1e9 + 7

using namespace std;

int main() {
  ll A, B, N;
  cin >> A >> B >> N;
  ll ans = 0;
  for (ll i = 1; i < N + 1; i++) {
    ll num = (A * i / B) - A * (i / B);
    ans = max(num, ans);
  }

  cout << ans << endl;
}