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

#include <bits/stdc++.h>
using namespace std;
int main() {
  long a, b, n;
  cin >> a >> b >> n;
  long tmp = min(b - 1, n);
  long ans = 0;
  int i = 0;
  while (tmp <= n) {
    ans = max(ans, (a * tmp) / b - a * (tmp / b));
    tmp += b;
    i++;
    if (i > a)
      break;
  }
  cout << ans << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  long a, b, n;
  cin >> a >> b >> n;
  long tmp = min(b - 1, n);
  long ans = 0;
  while (tmp <= n) {
    ans = max(ans, (a * tmp) / b - a * (tmp / b));
    tmp += b;
  }
  cout << ans << 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++)
//----------------------------------------------------------------------

using namespace std;
using ll = long long;
using P = pair<int, int>;
using Graph = vector<vector<int>>;

ll a, b, n;
ll func(ll x) { return floor((double)(a * x) / b) - a * floor((double)x / b); }

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


Error: TLE

Fixed submission:

//----------------------------------------------------------------------
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
//----------------------------------------------------------------------

using namespace std;
using ll = long long;
using P = pair<int, int>;
using Graph = vector<vector<int>>;

ll a, b, n;
ll value(int x) {
  return floor((double)a * x / (double)b) - a * floor(double(x) / (double)b);
}

int main(void) {
  cin >> a >> b >> n;
  map<ll, ll> freq;

  ll ans = 0;
  for (int i = 0; i <= n; ++i) {
    ll tmp = value(i);
    ans = max(ans, tmp);
    if (freq[tmp] > 1) {
      break;
    }
  }
  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##_len = (int)(n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (int)(n); i <= i##_len; i++)
#define rrep(i, n) for (int i = (int)(n)-1; 0 <= i; i--)
#define rrep1(i, n) for (int i = (int)(n); 1 <= i; i--)

#define each(it, c)                                                            \\
  for (__typeof((c).begin()) it = (c).begin(); it != (c).end(); it++)
#define all(obj) (obj).begin(), (obj).end()

#define pcount __builtin_popcount
#define SZ(x) ((int)(x).size())
#define LEN(x) ((int)(x).length())

#define dump(x) cerr << #x << " = " << (x) << endl;

#define endl "\\n"

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 (b < a) {
    a = b;
    return 1;
  }
  return 0;
}

typedef long long lint;

using namespace std;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  lint a, b, n, max = -1;
  cin >> a >> b >> n;
  if (b - 1 <= n) {
    lint mod = n % b;
    lint num = n - mod - 1;
    max = floor(a * num * 1.0 / b) - a * floor(num * 1.0 / b);
  } else {
    max = floor(a * n * 1.0 / b) - a * floor(n * 1.0 / b);
  }
  cout << max << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0, i##_len = (int)(n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (int)(n); i <= i##_len; i++)
#define rrep(i, n) for (int i = (int)(n)-1; 0 <= i; i--)
#define rrep1(i, n) for (int i = (int)(n); 1 <= i; i--)

#define each(it, c)                                                            \\
  for (__typeof((c).begin()) it = (c).begin(); it != (c).end(); it++)
#define all(obj) (obj).begin(), (obj).end()

#define pcount __builtin_popcount
#define SZ(x) ((int)(x).size())
#define LEN(x) ((int)(x).length())

#define dump(x) cerr << #x << " = " << (x) << endl;

#define endl "\\n"

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 (b < a) {
    a = b;
    return 1;
  }
  return 0;
}

typedef long long lint;

using namespace std;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  lint a, b, n, max = -1;
  cin >> a >> b >> n;
  if (b - 1 <= n) {
    lint mod = n % b;
    lint num = n - mod - 1;
    max = floor(a * num * 1.0 / b) - a * floor(num * 1.0 / b);
  } else {
    for (lint i = n; 1 <= i; i--) {
      lint tmp = floor(a * i * 1.0 / b) - a * floor(i * 1.0 / b);
      chmax(max, tmp);
      if (i % b == b - 1)
        break;
    }
  }
  cout << max << endl;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

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

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

  return 0;
}


Error: TLE

Fixed submission:

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

int main() {
  ll a, b, n;
  cin >> a >> b >> n;
  ll ans = 0;
  ll cnt = 0;
  while (true) {
    ans = max((ll)(a * n / b) - a * (ll)(n / b), ans);
    n--;
    cnt++;
    if (cnt == 1000000000 || n == 0)
      break;
  }
  cout << ans << "\\n";
  return 0;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define ll long long
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(0);
  ll a, b, n;
  cin >> a >> b >> n;
  chmin(n, b - 1);
  cout << floor(1.0 * a * n / b) - a * floor(1.0 * n / b) << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define lli long long int
#define MOD 1000000007
#define INF INT_MAX     // 2147483647
#define INFLL LLONG_MAX // 9223372036854775807
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repf(i, n) for (int i = 1; i < (int)(n + 1); i++)
#define all(v) v.begin(), v.end()
#define endl "\\n"
#define vi vector<lli>
#define vvi vector<vector<lli>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(10);

  lli a, b, n;
  cin >> a >> b >> n;

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

#include <bits/stdc++.h>

#ifdef NON_SUBMIT
#define TEST(n) (n)
#define tout cerr
#else
#define TEST(n) ((void)0)
#define tout cin
#endif

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  TEST(freopen("input.txt", "r", stdin));
  TEST(freopen("output.txt", "w", stdout));
  TEST(freopen("debug.txt", "w", stderr));
  long long ans = 0, res, B, s = 1, e, N;
  int A;
  cin >> A >> B >> N;
  e = N;
  while (s <= e) {
    long long m = (s + e) >> 1;
    if (m * B - 1 > N)
      e = m - 1;
    else
      s = m + 1;
  }
  if (e == 0)
    res = N;
  else
    res = e * B - 1;
  ans = max({A * res / B - res / B * A, A * N / B - N / B * A, 0LL});
  if (B - 1 <= N)
    ans = max(ans, A * (B - 1) / B);
  cout << ans << '\\n';
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

#ifdef NON_SUBMIT
#define TEST(n) (n)
#define tout cerr
#else
#define TEST(n) ((void)0)
#define tout cin
#endif

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  TEST(freopen("input.txt", "r", stdin));
  TEST(freopen("output.txt", "w", stdout));
  TEST(freopen("debug.txt", "w", stderr));
  long long ans = 0, B, s = 1, e, N;
  int A;
  cin >> A >> B >> N;
  e = N;
  while (s <= e) {
    long long m = (s + e) > 1;
    if (m * B - 1 > N)
      e = m - 1;
    else
      s = m + 1;
  }
  if (e == 0)
    ans = N;
  else
    ans = e * B - 1;
  cout << 1LL * A * ans / B - ans / B * A << '\\n';
  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 = min(n, b - 1);
  cout << ((a * (x % b)) - ((a * (x % b)) % b)) / b << 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;
  long long x = 0, y = min(b - 1, n);
  vector<int> ans;
  while (((a * x) / b) - (a * (x / b)) < a && x <= y) {
    ans.push_back(((a * x) / b) - (a * (x / b)));
    x++;
  }
  sort(ans.begin(), ans.end());
  reverse(ans.begin(), ans.end());
  cout << ans.at(0) << endl;
  return 0;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;

int main(void) {
  int64_t A, B, N, ans, x;

  ans = 0;

  cin >> A >> B >> N;

  x = min(B - 1, N);

  ans = (A * x) / B;

  cout << ans << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

int main(void) {
  int64_t A, B, N, i, K, k1, k2, ans;

  ans = 0;

  cin >> A >> B >> N;

  for (i = 1; i <= N; i++) {
    k1 = (A * i) / B;
    k2 = i / B;

    K = k1 - (A * k2);
    ans = max(ans, K);
  }

  cout << ans << endl;

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

#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < n; i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define reprr(i, m, n) for (ll i = m; i < n; i++)
#define INF 2e15
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;

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

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < n; i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define reprr(i, m, n) for (ll i = m; i < n; i++)
#define INF 2e15
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;

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

  ll x = b - 1;
  ll max_num = -INF;
  while (x <= n) {
    ll num = (a * x / b) - (a * (x / b));
    max_num = max(max_num, num);
    x += b;
  }
  cout << max_num << endl;
  return 0;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

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

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

Error: TLE

Fixed submission:

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

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

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

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

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

Error: TLE

Fixed submission:

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

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

#include "cmath"
#include "iostream"
#define endl '\\n'

using namespace std;

long long a, b, n;

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  cin >> a >> b >> n;

  long long max_ = 0;

  long long max_x = min(b - 1, n);
  long long min_x = 0;

  cout << max(f(min_x), f(max_x));

  return 0;
}

Error: TLE

Fixed submission:

#include "cmath"
#include "iostream"
#define endl '\\n'

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  long long a, b, n;

  cin >> a >> b >> n;

  long long max_ = 0;

  for (long long x = min(b - 1, n); x >= 0; x--) {
    long long temp = floorl((a * x) / b) - (a * floorl(x / b));
    if (temp > max_) {
      max_ = temp;
    }
  }

  cout << max_;

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

#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define int long long

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define rep1(i, n) for (int i = 1; i <= (int)n; ++i)
#define rrep(i, n) for (int i = (int)n - 1; i >= 0; --i)
#define rrep1(i, n) for (int i = n; i >= 1; --i)
#define range(i, l, r) for (int i = l; i < (int)r; ++i)
#define rrange(i, l, r) for (int i = (int)r - 1; i >= (int)l; --i)
#define unless(a) if (!(a))
#define all(a) begin(a), end(a)
#define fst first
#define scd second
#define PB emplace_back
#define PPB pop_back

using vi = vector<int>;
using pii = pair<int, int>;

bool chmin(int &a, int b) { return a > b ? (a = b, true) : false; }
bool chmax(int &a, int b) { return a < b ? (a = b, true) : false; }
int read() {
  int a;
  scanf("%lld", &a);
  return a;
}
constexpr int TEN(int n) { return n == 0 ? 1 : 10 * TEN(n - 1); }

int f(int a, int b) { return a / b; }

signed main() {
  int A, B, N;
  cin >> A >> B >> N;
  int m = min(B - 1, N);

  cout << A * m / B - A * (m / B) << endl;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define int long long

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define rep1(i, n) for (int i = 1; i <= (int)n; ++i)
#define rrep(i, n) for (int i = (int)n - 1; i >= 0; --i)
#define rrep1(i, n) for (int i = n; i >= 1; --i)
#define range(i, l, r) for (int i = l; i < (int)r; ++i)
#define rrange(i, l, r) for (int i = (int)r - 1; i >= (int)l; --i)
#define unless(a) if (!(a))
#define all(a) begin(a), end(a)
#define fst first
#define scd second
#define PB emplace_back
#define PPB pop_back

using vi = vector<int>;
using pii = pair<int, int>;

bool chmin(int &a, int b) { return a > b ? (a = b, true) : false; }
bool chmax(int &a, int b) { return a < b ? (a = b, true) : false; }
int read() {
  int a;
  scanf("%lld", &a);
  return a;
}
constexpr int TEN(int n) { return n == 0 ? 1 : 10 * TEN(n - 1); }

int f(int a, int b) { return a / b; }

signed main() {
  int A, B, N;
  cin >> A >> B >> N;
  int mx = 0;
  range(i, 0, 1000 * A) {
    if (N - i >= 0)
      chmax(mx, f(A * (N - i), B) - A * f(N - i, B));
  }
  printf("%lld\\n", mx);
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define rep(i, a, b) for (ll i = ll(a); i < ll(b); i++)
#define irep(i, a, b) for (ll i = ll(a); i >= ll(b); i--)
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
#define pb push_back
#define mp make_pair
#define F .first
#define S .second
using ll = long long;
using ld = long double;
const ll INF = 1LL << 60;
const ll mod = 1e9 + 7;
using namespace std;
ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }

int main() {
  ll a, b, n, ans = 0;
  cin >> a >> b >> n;
  ll c = GCD(a, b);
  ll d = n * c / (GCD(n, c));
  rep(i, max((ll)0, d - a), min(n, d + a) + 1) ans =
      max(ans, (a * i) / b - a * (i / b));
  // rep(i,0,min(n,b))ans=max(ans,(a*i)/b-a*(i/b));
  ll aa = min((ll)n, b - 1);
  ll bb = max((ll)0, b - 10000000);
  irep(i, aa, bb) ans = max(ans, (a * i) / b - a * (i / b));
  cout << ans;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, a, b) for (ll i = ll(a); i < ll(b); i++)
#define irep(i, a, b) for (ll i = ll(a); i >= ll(b); i--)
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
#define pb push_back
#define mp make_pair
#define F .first
#define S .second
using ll = long long;
using ld = long double;
const ll INF = 1LL << 60;
const ll mod = 1e9 + 7;
using namespace std;
ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }

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

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


Error: TLE

Fixed submission:

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

#include <algorithm>
#include <iostream>
using namespace std;
typedef long long ll;
ll a, b, n;
int main() {
  cin >> a >> b >> n;
  ll x;
  ll ans;
  if (n < b) {
    ans = (a * n) / b - a * (n / b);
    cout << ans;
    return 0;
  } else if (n == b) {
    x = n - 1;
    ans = (a * n) / b - a * (n / b);
    ll ans1 = (a * x) / b - a * (x / b);
    ans = max(ans, ans1);
    cout << ans;
  } else {
    ll maxn = (a * n) / b - a * (n / b);
    ll tmp;
    ll num = n / b;
    ll mod = 1e7;
    if (num > mod) {
      for (ll i = 1; i <= mod; i++) {
        ll mul = i * b - 1;
        tmp = (a * mul) / b - a * (mul / b);
        maxn = max(maxn, tmp);
      }
    } else {
      for (ll i = num; i >= 1; i--) {
        ll mul = i * b - 1;
        tmp = (a * mul) / b - a * (mul / b);
        maxn = max(maxn, tmp);
      }
    }
    ans = maxn;
    cout << ans;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
using namespace std;
typedef long long ll;
ll a, b, n;
int main() {
  cin >> a >> b >> n;
  ll x;
  ll ans;
  if (n < b) {
    ans = (a * n) / b - a * (n / b);
    cout << ans;
    return 0;
  } else if (n == b) {
    x = n - 1;
    ans = (a * n) / b - a * (n / b);
    ll ans1 = (a * x) / b - a * (x / b);
    ans = max(ans, ans1);
    cout << ans;
  } else {
    ll maxn = (a * n) / b - a * (n / b);
    ll tmp;
    ll num = n / b;
    for (ll i = num; i >= 1; i--) {
      ll mul = i * b - 1;
      tmp = (a * mul) / b - a * (mul / b);
      maxn = max(maxn, tmp);
    }
    ans = maxn;
    cout << ans;
  }
  return 0;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

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

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

  cin >> a >> b >> n;
  long long max = 0;
  long double op = min(b - 1, n);
  //   for(long double i=1;i<=op;i++)
  //   {

  //      long double p= i/b;

  //      // cout<<p<<endl;
  //      long long  j=  a* floor(p);
  //      long  long f= floor(a*p);
  //       long long ans=f-j;
  //      //  cout<<ans<<endl;
  //       if(max<ans)
  //       max=ans;

  //   }

  long long ans = a * (op / b);
  cout << ans;
  return 0;
}

Error: TLE

Fixed submission:

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

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

  cin >> a >> b >> n;
  long long max = 0;
  long long op = min(b - 1, n);
  for (long double i = 1; i <= op; i++) {

    long double p = i / b;

    // cout<<p<<endl;
    long long j = a * floor(p);
    long long f = floor(a * p);
    long long ans = f - j;
    //  cout<<ans<<endl;
    if (max < ans)
      max = ans;
  }
  cout << max;
  return 0;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;

int main() {
  ll A, B, N;
  cin >> A >> B >> N;
  ll ans = 0;
  if (N < B - 1) {
    cout << floor((A * N) / B) - A * floor(N / B) << endl;
    return 0;
  }
  /*for(int i = 1;; i++){
      ll X = B*i-1;
      if(X > N) break;
      ll temp = floor((A*X)/B)- A* floor(X / B);
      ans = max(ans, temp);
  }*/
  ll X = (N / B + 1) * B - 1;
  while (X > N)
    X -= B;
  // cout << X << endl;
  cout << floor((A * X) / B) - A * floor(X / B) << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;

int main() {
  long double A, B, N;
  cin >> A >> B >> N;
  ll ans = 0;
  if (N < B - 1) {
    cout << floor((A * N) / B) - A * floor(N / B) << endl;
    return 0;
  }
  for (int i = 1;; i++) {
    ll X = B * i - 1;
    if (X > N)
      break;
    ll temp = floor((A * X) / B) - A * floor(X / B);
    ans = max(ans, temp);
  }
  cout << ans << endl;
}