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

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

// Made with <3 by MinumCoklatPanas
typedef unsigned long long ll;
const int INF = 1e9;
const ll INFF = 1e18;
const int MAXN = 510;
const int MOD = 1e9 + 7;
const double PI = acos(-1.0);
const double INFD = 1E9;
const double EPS = 1e-9;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ll a, b, n;
  cin >> a >> b >> n;
  // assert(a != b);
  ll mx = (n / b) * b;
  if (mx == n && n != 1)
    --mx;
  else
    mx = n;
  mx = max(mx, 1ull);
  // cout << mx << endbl;
  ll ans = ((mx * a) / b) - (a * (mx / b));
  ll mn = min(n, b - 1);
  ll tmp = ((mn * a) / b) - (a * (mn / b));
  ans = max(ans, tmp);
  cout << max(ans, 0ull) << endl;
  return 0;
}

Error: WA

Fixed submission:

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

// Made with <3 by MinumCoklatPanas
typedef unsigned long long ll;
const int INF = 1e9;
const ll INFF = 1e18;
const int MAXN = 510;
const int MOD = 1e9 + 7;
const double PI = acos(-1.0);
const double INFD = 1E9;
const double EPS = 1e-9;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ll a, b, n;
  cin >> a >> b >> n;
  assert(a != b);
  ll mx = (n / b) * b;
  if (mx == n && n != 1)
    --mx;
  else
    mx = n;
  mx = max(mx, 1ull);
  cout << mx << endl;
  ll ans = ((mx * a) / b) - (a * (mx / b));
  cout << max(ans, 0ull) << endl;
  return 0;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

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

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


Error: TLE

Fixed submission:

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

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

#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>

using namespace std;
using LLONG = long long;
const LLONG MOD = 1000000007;

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

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>

using namespace std;
using LLONG = long long;
const LLONG MOD = 1000000007;

int main() {
  LLONG A, B, N;
  cin >> A >> B >> N;
  LLONG ans = 0;
  for (LLONG x = N - max(A, B); x <= N; ++x) {
    LLONG t1 = A * x / B;
    LLONG t2 = x / B;
    t2 *= A;
    ans = max(ans, t1 - t2);
  }
  cout << ans << endl;
}
Problem p02696 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
const ll INF = 2e18;
const int inf = 1e9 + 10;
const int maxN = 200010;
const int maxD = 15;
const int maxH = 100;
const int MOD = 1000000007;

ll x, y, n;
int main() {

  scanf("%lld%lld%lld", &x, &y, &n);
  ll t = min(y - 1, n);
  ll ans = (x * t) / y - x * (t / y);
  cout << ans << endl;
  return 0;
}

Error: -8

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
const ll INF = 2e18;
const int inf = 1e9 + 10;
const int maxN = 200010;
const int maxD = 15;
const int maxH = 100;
const int MOD = 1000000007;

ll x, y, n;
int main() {
  freopen("a.txt", "r", stdin);
  freopen("b.txt", "w", stdout);

  scanf("%lld%lld%lld", &x, &y, &n);
  ll t = min(y - 1, n);
  ll ans = (x * t) / y - x * (t / y);
  cout << ans << endl;
  return 0;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int floor(ll x, ll y) { return x / y; }

int main() {
  ll A, B, N;
  cin >> A >> B >> N;
  if (B == 1)
    cout << 0 << endl;
  else {
    if (N < B) {
      ll C = floor(A * N, B) - A * floor(N, B);
      cout << C << endl;
    } else {
      ll D = floor(A * (B - 1), B) - A * floor((B - 1), B);
      cout << D << endl;
    }
  }
}

Error: TLE

Fixed submission:

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

int floor(ll &x, ll &y) { return x / y; }

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

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

Error: TLE

Fixed submission:

/* In the name of Allah */
#include <bits/stdc++.h>
using namespace std;
long long a, b, n, maxx, z;
int main() {
  cin >> a >> b >> n;
  for (int i = 1; i <= n; i++) {
    z = floor((a * i) / b) - (a * floor(i / b));
    maxx = max(z, maxx);
  }
  cout << maxx;
  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 < (n); i++)
#define rrep(i, m, n) for (int i = (m); i < (n); i++)
#define fore(i, a) for (auto &i : a)
#define debug(a, b) cout << "debug : " << a << " , " << b << endl
using ll = long long;
const ll INF = 1LL << 60;
const ll mod = 1E9 + 7;

int main() {
  ll a, b, n;
  cin >> a >> b >> n;
  auto f = [&](ll x) {
    ll xb = x / b;
    return a * x / b - a * xb;
  };
  cout << max(f(n), f(n - 1 - n % b));
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, m, n) for (int i = (m); i < (n); i++)
#define fore(i, a) for (auto &i : a)
#define debug(a, b) cout << "debug : " << a << " , " << b << endl
using ll = long long;
const ll INF = 1LL << 60;
const ll mod = 1E9 + 7;

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

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ul unsigned long long int
#define ld long double
#define f(t) for (ll i = 0; i < t; i++)
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define ff first
#define ss second
#define MOD 1000000007
#define inf 4e18
#define EPS 1e-3
#define PI 3.1415926535897932385
#define display(v) f(v.size()) cout << v[i] << " "
const double h = 1e-6;
const int MAX_ = 200005;
#define all(v) v.begin(), v.end()

inline ll mul(ll a, ll b) { return (a * 1ll * b) % MOD; }
inline ll sub(ll a, ll b) {
  ll c = a - b;
  if (c < 0)
    c += MOD;
  return c;
}
inline ll add(ll a, ll b) {
  ll c = a + b;
  if (c > MOD)
    c -= MOD;
  return c;
}
ll sqr(ll x) { return x * x; }
//////////////////////*********CODE***********/////////////////////
//////////////////////////////////////////////////////////////////
ll val(ll a, ll b, ll mid) {
  ll res = (a * mid) / b - a * (mid / b);
  return res;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ll a, b, n;
  cin >> a >> b >> n;
  ll go = min(b - 1, n);
  cout << val(a, b, go);

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ul unsigned long long int
#define ld long double
#define f(t) for (ll i = 0; i < t; i++)
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define ff first
#define ss second
#define MOD 1000000007
#define inf 4e18
#define EPS 1e-3
#define PI 3.1415926535897932385
#define display(v) f(v.size()) cout << v[i] << " "
const double h = 1e-6;
const int MAX_ = 200005;
#define all(v) v.begin(), v.end()

inline ll mul(ll a, ll b) { return (a * 1ll * b) % MOD; }
inline ll sub(ll a, ll b) {
  ll c = a - b;
  if (c < 0)
    c += MOD;
  return c;
}
inline ll add(ll a, ll b) {
  ll c = a + b;
  if (c > MOD)
    c -= MOD;
  return c;
}
ll sqr(ll x) { return x * x; }
//////////////////////*********CODE***********/////////////////////
//////////////////////////////////////////////////////////////////
ll val(ll a, ll b, ll mid) {
  ll res = (a * mid) / b - a * (mid / b);
  return res;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ll a, b, n;
  cin >> a >> b >> n;
  ll l = 1, r = n;
  ll ans = 0;

  while (l < r) {
    ll mid = (l + r) / 2;
    ll lft = val(a, b, l);
    ll rgh = val(a, b, r);
    ll mm = val(a, b, mid);
    ans = max({ans, lft, rgh});
    if (mm >= lft) {
      l = mid + 1;
      ans = max(mm, ans);
    } else if (rgh <= mm) {
      r = mid - 1;
      ans = max(ans, mm);
    }
  }
  ll lf = val(a, b, l);
  ll rr = val(a, b, r);
  ans = max(ans, rr);
  ans = max(ans, lf);
  cout << ans;

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

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

long inf = 1000000007;

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

  if (n < b - 1) {
    i = n;
  } else {
    i = b - 1;
  }

  score = (a * i) / b - a * (i / b);

  cout << score << endl;
}


Error: WA

Fixed submission:

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

long inf = 1000000007;

int main() {
  long a, b, n;
  cin >> a >> b >> n;
  long score = 0;
  long i = n;
  while (i % (b - 1) != 0) {
    i--;
  }
  score = (a * i) / b - a * (i / b);

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

#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <string>
#include <vector>
using namespace std;

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

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

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

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <string>
#include <vector>
using namespace std;

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

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

int main() {
  ll A, B, N;
  cin >> A >> B >> N;
  ll mx = 0;
  for (int i = 1; i <= N; i++) {
    mx = max(mx, func(A, B, i));
  }
  cout << mx << endl;
  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 (ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for (ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for (ll i = (n)-1; i >= 0; i--)
#define rreps(i, e, n) for (ll i = (n)-1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())
#define endl "\\n"

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  // ifstream in("input.txt");
  // cin.rdbuf(in.rdbuf());
  ll a, b, n;
  cin >> a >> b >> n;
  ll ans = 0;
  if (b > n) {
    cout << f(a, b, n) << endl;
  } else {
    cout << f(a, b, b - 1) << 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##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for (ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for (ll i = (n)-1; i >= 0; i--)
#define rreps(i, e, n) for (ll i = (n)-1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())
#define endl "\\n"

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  // ifstream in("input.txt");
  // cin.rdbuf(in.rdbuf());
  ll a, b, n;
  cin >> a >> b >> n;
  ll ans = 0;
  bool plus = false;
  rep(i, n + 1) {
    ll v = f(a, b, i);
    if ((v == 0) && (plus))
      break;
    if (v > 0)
      plus = true;
    ans = max(ans, v);
  }
  cout << ans << endl;
  return 0;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

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

const ll INF = 1e18;
const int MX = 2005;

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

Error: TLE

Fixed submission:

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

const ll INF = 1e18;
const int MX = 2005;

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

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

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

  double tgt = min(b, n);
  // float diff = 10.0;
  long long ans = 0;
  for (long long i = (long long)tgt; i >= 1; i--) {
    long long tmp;
    tmp = floor(a * i / b) - a * floor(i / b);
    ans = max(ans, tmp);
    if (tmp < ans) {
      break;
    }
  }

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

Error: TLE

Fixed submission:

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

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

  double tgt = min(b, n);
  // float diff = 10.0;
  long long ans = 0;
  for (long long i = 1; i <= (long long)tgt; i++) {
    long long tmp;
    tmp = floor(a * i / b) - a * floor(i / b);
    ans = max(ans, tmp);
  }

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

#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define PI 3.141592
#define MOD7 1000000007
#define LL_INF 9000000000000000000
#define LL_MINF -9000000000000000000
#define INT_INF 2000000000
#define INT_MINF -2000000000
#define all(a) (a).begin(), (a).end()
#define fi first
#define se second
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

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

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

Error: TLE

Fixed submission:

#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define PI 3.141592
#define MOD7 1000000007
#define LL_INF 9000000000000000000
#define LL_MINF -9000000000000000000
#define INT_INF 2000000000
#define INT_MINF -2000000000
#define all(a) (a).begin(), (a).end()
#define fi first
#define se second
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

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

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

Error: TLE

Fixed submission:

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

#include <algorithm>
#include <bits/stdc++.h>
#include <iostream>
#include <iterator>
#include <math.h>
#include <numeric>
#include <sstream>
#include <string>
#include <vector>

using namespace std;

#define endl ("\\n")
#define pi (3.141592653589)
#define mod 1000000007
#define int int64_t
#define float double
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(c) c.begin(), c.end()
#define min3(a, b, c) min(c, min(a, b))
#define min4(a, b, c, d) min(d, min(c, min(a, b)))
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
#define rep(i, n) for (int i = 0; i < n; i++)
#define fast                                                                   \\
  ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)

struct debugger {
  template <typename T> debugger &operator,(const T &v) {
    cerr << v << " ";
    return *this;
  }
} dbg;

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

  int res = A * min(N, B - 1) / B;
  cout << res << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <bits/stdc++.h>
#include <iostream>
#include <iterator>
#include <math.h>
#include <numeric>
#include <sstream>
#include <string>
#include <vector>

using namespace std;

#define endl ("\\n")
#define pi (3.141592653589)
#define mod 1000000007
#define int int64_t
#define float double
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(c) c.begin(), c.end()
#define min3(a, b, c) min(c, min(a, b))
#define min4(a, b, c, d) min(d, min(c, min(a, b)))
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
#define rep(i, n) for (int i = 0; i < n; i++)
#define fast                                                                   \\
  ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)

struct debugger {
  template <typename T> debugger &operator,(const T &v) {
    cerr << v << " ";
    return *this;
  }
} dbg;

int32_t main() {
  fast;
  int A, B, N;
  cin >> A >> B >> N;
  int res = floor(A * N / B) - A * floor(N / B);
  for (int i = N - 1; i >= N / 10; i--) {
    if (floor(A * i / B) - A * floor(i / B) > res) {
      res = floor(A * i / B) - A * floor(i / B);
    }
  }
  cout << res;
  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;
  if (b <= n) {
    x = b - 1;
  } else {
    x = n;
  }
  long long res = (a * x) / b - (a * (x / b));
  cout << res;
}

Error: TLE

Fixed submission:

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

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;
typedef long double ld;

#define sz(a) int((a).size())
#define forn(i, n) for (int i = 0; i < int(n); ++i)
#define fore(i, l, r) for (int i = int(l); i < int(r); ++i)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define file_name(a)                                                           \\
  (freopen(((string)(a) + ".in").c_str(), "r", stdin),                         \\
   freopen(((string)(a) + ".out").c_str(), "w", stdout))

int nxt() {
  int x;
  cin >> x;
  return x;
}

int main() {
  ll a, b, n;
  cin >> a >> b >> n;
  if (b == 1) {
    cout << 0 << '\\n';
    return 0;
  }
  ll ans = 0;
  for (ll x = min(b - 1, n); x <= n; x += b) {
    ans = max(ans, (a * x) / b - a * (x / b));
  }
  cout << ans << '\\n';
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;
typedef long double ld;

#define sz(a) int((a).size())
#define forn(i, n) for (int i = 0; i < int(n); ++i)
#define fore(i, l, r) for (int i = int(l); i < int(r); ++i)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define file_name(a)                                                           \\
  (freopen(((string)(a) + ".in").c_str(), "r", stdin),                         \\
   freopen(((string)(a) + ".out").c_str(), "w", stdout))

int nxt() {
  int x;
  cin >> x;
  return x;
}

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

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

int main() {
  ll A, B, N, i, p;
  cin >> A >> B >> N;

  if (N < B) {
    p = N;
  } else {
    p = B - 1;
  }

  cout << A * p / B - A * (p / B) << endl;
  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  ll A, B, N, i, max = 0, p, t;
  cin >> A >> B >> N;

  rep(i, N + 1) {
    p = A * i / B - A * (i / B);
    if (max < p) {
      max = p;
    }
  }

  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 ans = 0;

  long long m = N;

  if (B - 1 < N)
    m = B - 1;

  ans = (A * (m % B)) / B;

  cout << ans << endl;
}

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 = 0;

  long long m = N;

  if (B < N)
    m = B;

  for (int i = 1; i <= m; i++) {
    long long y;
    y = (A * (i % B) - (A * i) % B) / B;
    if (y > ans) {
      ans = y;
    }
  }
  cout << ans << endl;
}
Problem p02696 (C++) — buggy submission, verdict: Runtime Error

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

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


Error: 0

Fixed submission:

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

signed main() {
  int A, B, N;
  cin >> A >> B >> N;
  cout << N / (abs(A - B)) << endl;
}