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

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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i, n) for (ll i = 0; i < (ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int, int>, int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
  std::fill((T *)array, (T *)(array + N), val);
}

// 最大公約数
ll gcd(ll a, ll b) {
  if (a % b == 0)
    return (b);
  else
    return (gcd(b, a % b));
}

// 最小公倍数
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }

int main() {
  cout << fixed << setprecision(15);
  ll A, B, N;
  cin >> A >> B >> N;

  ll x;
  ll ans = 0;
  x = B - 1;
  ll count = 0;
  while (x <= N) {
    ll a = (A * x) / B;
    ll t = x / B;
    ll b = A * t;
    ans = max(ans, a - b);
    x = x + B;
    count++;
    if (count >= 100000)
      break;
  }
  ll a = (A * N) / B;
  ll t = N / B;
  ll b = A * t;
  ans = max(ans, a - b);

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

Error: TLE

Fixed submission:

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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i, n) for (ll i = 0; i < (ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int, int>, int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
  std::fill((T *)array, (T *)(array + N), val);
}

// 最大公約数
ll gcd(ll a, ll b) {
  if (a % b == 0)
    return (b);
  else
    return (gcd(b, a % b));
}

// 最小公倍数
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }

int main() {
  cout << fixed << setprecision(15);
  ll A, B, N;
  cin >> A >> B >> N;

  ll x;
  ll ans = 0;
  x = B - 1;
  while (x <= N) {
    ll a = (A * x) / B;
    ll t = x / B;
    ll b = A * t;
    ans = max(ans, a - b);
    x = x + B;
  }
  ll a = (A * N) / B;
  ll t = N / B;
  ll b = A * t;
  ans = max(ans, a - b);

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

#include <bits/stdc++.h>

using namespace std;

// ショートハンド
// #define ll intに変えればメモリ節約
#define ll long long

/*
 * ループ系のマクロ
 * `REP(i, 10) { cout << i; }`のように、変数名,回数で動く
 */
#define REPS(i, a, n) for (ll i = (a); i < (ll)(n); ++i)
#define REP(i, n) REPS(i, 0, n)
#define RREP(i, n) REPS(i, 1, n + 1)
#define DEPS(i, a, n) for (ll i = (a); i >= (ll)(n); --i)
#define DEP(i, n) DEPS(i, n, 0)
#define EACH(i, n) for (auto &&i : n)

/*
 * 正規表現系
 */
#define MATCH(_str, _ptn) regex_match(_str, regex(_ptn))
#define REPLACE(_str, _ptn, _replacement)                                      \\
  regex_replace(_str, regex(_ptn), _replacement)

const int MOD = 1e9 + 7;

ll a, b, n, x;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  cin >> a >> b >> n;
  x = min(b - 1, n);
  cout << fixed << a * x / b - x / b;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl;
#define ll long long
#define REPS(i, a, n) for (ll i = (a); i < (ll)(n); ++i)
#define REP(i, n) REPS(i, 0, n)
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
using namespace std;
int main() {
  ll a, b, n, max = 0;
  cin >> a >> b >> n;
  REPS(i, b / a, n + 1) {
    ll tmp = (ll)(a * i / b) - a * (ll)(i / b);
    if (tmp < max) {
      cout << fixed << max;
      return 0;
    }
    chmax(max, tmp);
  }
  cout << fixed << max;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

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

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

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


Error: TLE

Fixed submission:

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

long a, b;

long fnc(long init, long n) {
  long out = 0;

  if (n == 1) {
    return (floor(a * n / b) - a * floor(n / b));
  }
  if (n == 2) {
    return max((floor(a * init / b) - a * floor(init / b)),
               (floor(a * (init + 1) / b) - a * floor((init + 1) / b)));
  }

  out = max(fnc(init, floor(n / 2)), fnc(init + n / 2, n - floor(n / 2)));

  return out;
}

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

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

#include <iostream>
using namespace std;

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


Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main(void) {
  long long a, b, num, max = 0;
  cin >> a >> b >> num;
  for (int i = 1; i <= num; i++) {
    long long temp = (a * i) / b - a * (i / b);
    if (max < temp) {
      max = temp;
    }
  }
  cout << max;
  return 0;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

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

long double a, b, n;

void solver() {
  cin >> a >> b >> n;

  long double x;
  if (n < b - 1) {
    x = n;
  } else {
    x = b - 1;
  }

  long double ans = floor(a * x / b) - a * floor(x / b);
  cout << ans << "\\n";
}

int main() { solver(); }


Error: TLE

Fixed submission:

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

void solver() {
  long double a, b, n;
  cin >> a >> b >> n;

  long double ans = -1000000000.0;
  long double prev = 0.0;
  for (long double i = 0; i <= n; i++) {
    long double tmp = floor(a * i / b) - a * floor(i / b);
    if (prev > tmp)
      break;
    ans = max(ans, tmp);
    prev = tmp;
  }

  cout << ans << "\\n";
}

int main() { solver(); }
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
// #define for(i,a,b) for(int i=(a);i<=(b);i++)
#define ppi pair<int, int>
#define fi first
#define se second
typedef long long ll;
typedef unsigned long long ull;
const ll inf = 0x3f3f3f3f3f3f3f3f;
const int N = 105;
const double pi = acos(-1.0);
const ll mod = 1e9 + 7;
void init() {
  ios::sync_with_stdio(false);
  cin.tie(0);
}
template <class T> inline void read(T &res) {
  char c;
  T flag = 1;
  while ((c = getchar()) < '0' || c > '9')
    if (c == '-')
      flag = -1;
  res = c - '0';
  while ((c = getchar()) >= '0' && c <= '9')
    res = res * 10 + c - '0';
  res *= flag;
}
int main() {
  init();
  ll a, b, n;
  cin >> a >> b >> n;
  if (n >= b)
    n = b - 1;
  cout << (ll)floor(a * n / b);
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
// #define for(i,a,b) for(int i=(a);i<=(b);i++)
#define ppi pair<int, int>
#define fi first
#define se second
typedef long long ll;
typedef unsigned long long ull;
const ll inf = 0x3f3f3f3f3f3f3f3f;
const int N = 105;
const double pi = acos(-1.0);
const ll mod = 1e9 + 7;
void init() {
  ios::sync_with_stdio(false);
  cin.tie(0);
}
template <class T> inline void read(T &res) {
  char c;
  T flag = 1;
  while ((c = getchar()) < '0' || c > '9')
    if (c == '-')
      flag = -1;
  res = c - '0';
  while ((c = getchar()) >= '0' && c <= '9')
    res = res * 10 + c - '0';
  res *= flag;
}
int main() {
  init();
  ll a, b, n, _max = -inf;
  cin >> a >> b >> n;
  for (ll i = 1; i <= n; i++)
    _max = max(_max, ll(floor(a * i / b) - a * floor(i / b)));
  cout << _max;
  return 0;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

// ABC165D -

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

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

  long long int ans = 0;
  if (N >= B - 1) {
    ans = A * (B - 1) / B;
  } else {
    ans = A * N / B;
  }

  cout << ans << endl;

  return 0;
}


Error: TLE

Fixed submission:

// ABC165D -

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

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

  long long int ans = N * A / B - N / B * A;
  for (long long int i = B - 1; i <= N; i += B) {
    if ((i * A / B - i / B * A) >= ans) {
      ans = i * A / B - i / B * A;
    }
  }

  cout << ans << 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;
  cout << (n < b ? (a * n / b) : (a * (b - 1) / b));
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main(void) {
  ios::sync_with_stdio(0);
  cin.tie(0);
  long long a, b, n, c;
  cin >> a >> b >> n;
  c = b / a;
  while (c <= n) {
    if (a * (c + (b - (a * c) % b) / a + 1) / b -
            a * ((c + (b - (a * c) % b) / a + 1) / b) <
        a * c / b - a * (c / b))
      break;
    c += (b - (a * c) % b) / a + 1;
  }
  if (c > n)
    cout << a * (c - 1) / b - a * ((c - 1) / b);
  else
    cout << a * c / b - a * (c / b);
  return 0;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;

int main() {

  /*#ifndef ONLINE_JUDGE
          freopen("input.txt", "r", stdin);
          freopen("output.txt", "w", stdout);
  #endif*/

  // const int INF = 1e9;
  long long a, b, n;
  cin >> a >> b >> n;

  // floor(ax/b) - a*floor(x/b)

  long long sum = 0;

  long long ans = 0;

  long long x = min(b - 1, n);

  sum = floor(a * x / b) - (a * floor(x / b));

  cout << sum;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

int main() {

  /*#ifndef ONLINE_JUDGE
          freopen("input.txt", "r", stdin);
          freopen("output.txt", "w", stdout);
  #endif*/

  // const int INF = 1e9;
  long long a, b, n;
  cin >> a >> b >> n;

  // floor(ax/b) - a*floor(x/b)

  long long sum = 0;

  long long ans = 0;
  long long x = 0;
  // long long xval=0;

  while (x <= n) {
    sum = floor(a * x / b) - (a * floor(x / b));

    if (sum > ans) {
      ans = sum;
      // xval =x;
    }
    // ans = max(ans, sum);
    // sum = 0;
    ++x;
  }

  cout << ans;
}
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;
  if (N >= B - 1) {
    ans = A * (B - 1) / B;
  } else {
    ans = A * N / B;
  }
  cout << ans << 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 max_fl;
  max_fl = 0;
  N = min(N, B);
  for (long long x = 0; x <= N; x++) {
    max_fl = max(max_fl, (long long)(A * (double)(x % B) / B));
  }
  cout << max_fl << endl;
  return 0;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <vector>
#define ll long long
#define SIZE_OF_ARRAY(array) (sizeof(array) / sizeof(array[0]))

using namespace std;

int gcd(int x, int y) { return (x % y) ? gcd(y, x % y) : y; }

int main() {
  ll A, B, N;
  cin >> A >> B >> N;
  ll tmp = 0;
  ll ans = 0;

  ll a = (A * N / B) - A * (N / B);
  ll b = (A * (B - 1) / B) - A * ((B - 1) / B);

  if (B <= N) {
    if (a >= b) {
      cout << a << endl;
    } else {
      cout << b << endl;
    }
  } else {
    cout << (A * N / B) - A * (N / B) << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <vector>
#define ll long long
#define SIZE_OF_ARRAY(array) (sizeof(array) / sizeof(array[0]))

using namespace std;

int gcd(int x, int y) { return (x % y) ? gcd(y, x % y) : y; }

int main() {
  ll A, B, N;
  cin >> A >> B >> N;
  ll tmp = 0;
  ll ans = 0;

  if (B <= N) {
    ans = A * (B - 1) / B;
    for (ll i = B + 1; i <= N; i++) {
      tmp = (A * N / B) - A * (N / B);
      if (ans <= tmp)
        ans = tmp;
    }
  } else {
    cout << (A * N / B) - A * (N / B) << endl;
    return 0;
  }

  cout << ans << endl;

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

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

int main() {
  long long a, b, c;
  cin >> a >> b >> c;
  if (c >= b)
    c = b - 1;
  cout << floor(a * c / b) - a * floor(c / b) << endl;
}

Error: TLE

Fixed submission:

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

int main() {
  long long a, b, n;
  cin >> a >> b >> n;
  long long z = floor(a / b) - a * floor(1 / b);
  for (int i = 2; i <= n; i++) {
    int z1 = floor(a * i / b) - a * floor(i / b);
    if (z1 > z)
      z = z1;
  }
  cout << z << endl;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

/*
No matter how long a night, dawn will always break.

Simular saying ... The darkest hour is just before the dawn.
 ***************************************   ************************8
**********************************
*/
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define double long double
#define pb push_back
#define pf push_front
#define pii pair<int, int>
#define vi vector<int>
#define vii vector<pii>
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define x first
#define y second
#define endl '\\n'
#define sz(x) (int)(x).size()
#define fo(i, l, u) for (i = l; i < u; i++)
#define rfo(i, l, u) for (i = l; i >= u; i--)
#define allfo(s) for (auto it = (s).begin(); it != (s).end(); it++)
#define _init(b) memset(b, -1, sizeof(b))
#define _init0(b) memset(b, 0, sizeof(b))
#define MOD 1000000007
#define hell 998244353
#define output(x) cout << (x ? "YES" : "NO") << endl;

int gcd(int a, int b) {
  if (a > b)
    swap(a, b);
  if (a == 0)
    return b;
  return gcd(b % a, a);
}
bool mod(double a, double b) { return a / b - floor(a / b); }

int f(int a, int b, int l, int r) {
  if (l > r)
    return 0;
  if (l / b == r / b) {
    return (a * r) / b - a * (r / b);
  }
  int mid = l + (r - l) / 2;
  return max(f(a, b, l, mid), f(a, b, mid + 1, r));
}

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int i, j, x, k, a, b;
  cin >> a >> b >> x;
  if (b < x) {
    cout << (a * (b - 1)) / b << endl;
    return 0;
  }
  cout << f(a, b, 1, x);

  return 0;
}

Error: TLE

Fixed submission:

/*
No matter how long a night, dawn will always break.

Simular saying ... The darkest hour is just before the dawn.
 ***************************************   ************************8
**********************************
*/
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define double long double
#define pb push_back
#define pf push_front
#define pii pair<int, int>
#define vi vector<int>
#define vii vector<pii>
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define x first
#define y second
#define endl '\\n'
#define sz(x) (int)(x).size()
#define fo(i, l, u) for (i = l; i < u; i++)
#define rfo(i, l, u) for (i = l; i >= u; i--)
#define allfo(s) for (auto it = (s).begin(); it != (s).end(); it++)
#define _init(b) memset(b, -1, sizeof(b))
#define _init0(b) memset(b, 0, sizeof(b))
#define MOD 1000000007
#define hell 998244353
#define output(x) cout << (x ? "YES" : "NO") << endl;

int gcd(int a, int b) {
  if (a > b)
    swap(a, b);
  if (a == 0)
    return b;
  return gcd(b % a, a);
}
bool mod(double a, double b) { return a / b - floor(a / b); }

int f(int a, int b, int l, int r) {
  if (l > r)
    return 0;
  if (l / b == r / b) {
    return (a * r) / b - a * (r / b);
  }
  int mid = l + (r - l) / 2;
  return max(f(a, b, l, mid), f(a, b, mid + 1, r));
}

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int i, j, x, k, a, b;
  cin >> a >> b >> x;
  cout << f(a, b, 1, x);

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

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

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int a, b, n, x = 1, p = 0, ans = 0;
  cin >> a >> b >> n;
  for (int i = 1; i <= n; i++) {
    p = (floor((a * x) / b) - a * floor(x / b));
    ans = max(ans, p);
    x++;
  }
  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 < (n); i++)
#define REP2(i, x, n) for (int i = x; i < (n); i++)
#define ALL(n) begin(n), end(n)
#define sz(x) int(x.size())
using ll = long long;
const ll LLINF = numeric_limits<long long>::max();
const int mod = 1000000007;
const int INF = 1001001001;

int main() {
  ll A, B, N;

  cin >> A >> B >> N;

  ll x = B - 1;
  if (x > N) {
    x = N;
  }
  cout << (A * x) / B - A * (x / B);
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define REP2(i, x, n) for (int i = x; i < (n); i++)
#define ALL(n) begin(n), end(n)
#define sz(x) int(x.size())
using ll = long long;
const ll LLINF = numeric_limits<long long>::max();
const int mod = 1000000007;
const int INF = 1001001001;

int main() {
  ll A, B, N;

  cin >> A >> B >> N;
  ll ma = 0;
  for (ll i = 1LL; i <= N; i++) {
    ll a = A * i / B;
    ll b = (i / B);
    ll c = a - A * b;

    if (ma < c) {
      ma = c;
    }
  }
  cout << ma;

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

#include <algorithm>
#include <cstdio>
using namespace std;
int main() {
  long long int a, b, n, k, i, minimum;
  scanf("%lld%lld%lld", &a, &b, &n);
  if (b > n) {
    printf("%lld", (a * n) / b);
  } else
    printf("%lld", (a * (b - 1)) / b);
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdio>
using namespace std;
int main() {
  long long int a, b, n, k, i, minimum;
  scanf("%lld%lld%lld", &a, &b, &n);
  if (b > n) {
    printf("%lld", (a * n) / b);
  } else if (b == n) {
    printf("%lld", (a * (b - 1)) / b);
  } else {
    k = 1;
    if (b == 1)
      k = 2;
    i = k * b - 1;
    minimum = 10000000000;
    while (i <= n) {
      minimum = min(minimum, (a * i) / b - a * (i / b));
      k++;
      i = k * b - 1;
    }
    printf("%lld", minimum);
  }
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

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

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

  ll m = min(n, b - 1);
  ll ans = 0;

  ll w = m / b;
  ll s = (a * m) / b;
  ll d = s - a * w;

  ans = d;

  cout << ans << endl;
}

Error: TLE

Fixed submission:

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

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

  ll m = min(n, b - 1);
  ll ans = 0;
  rep(x, m) {
    ll w = x / b;
    ll s = (a * x) / b;
    ll d = s - a * w;

    ans = max(ans, d);
    if (ans == a - 1)
      break;
  }
  cout << ans << endl;
}
Problem p02696 (C++) — buggy submission, verdict: Runtime Error

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

#define INF 1000000000000

signed main() {
  int a, b, n;
  cin >> a >> b >> n;
  if (n <= b - 1) {
    cout << (a * n) / b - (n / b) * a;
    exit(0);
  };
  int ans = 0;
  rep(i, n / b + 1) {
    if (b * (i + 1) - 1 <= n)
      ans = max(ans, (a * (b * (i + 1) - 1)) / b - ((b * (i + 1) - 1) / b) * a);
    if (ans == b - 1) {
      break;
    }
  }
  cout << ans;
}


Error: WA

Fixed submission:

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

#define INF 1000000000000

signed main() {
  int a, b, n;
  cin >> a >> b >> n;
  int tamesu[n / b + 1];
  rep(i, n / b + 1) {
    if (i == 0) {
      if (b - 1 > n) {
        tamesu[0] = n;
        continue;
      }
    }
    tamesu[i] = b * (i + 1) - 1;
  }
  int ans = 0;
  rep(i, n / b + 1) {
    ans = max(ans, (a * tamesu[i]) / b - (tamesu[i] / b) * a);
    if (ans == b - 1) {
      break;
    }
  }
  cout << ans;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define f(i, j, k) for (int i = j; i < k; i++)
using namespace std;
int main() {
  long long a, b, c, ans = 0, j;
  cin >> a >> b >> c;
  j = c / b;
  if (b == 1) {
    cout << 0 << endl;
    return 0;
  }
  f(i, 1, j + 1) {
    if (ans < floor(a * (b * i - 1) / b) - a * floor((b * i - 1) / b)) {
      ans = floor(a * (b * i - 1) / b) - a * floor((b * i - 1) / b);
    }
    if (ans == a - 1 - a / b) {
      cout << a - 1 - a / b << endl;
      return 0;
    }
  }
  if (ans < floor(a * c / b) - a * floor(c / b)) {
    ans = floor(a * c / b) - a * floor(c / b);
  }
  cout << ans << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define f(i, j, k) for (int i = j; i < k; i++)
using namespace std;
int main() {
  long long a, b, c, ans = 0, j;
  cin >> a >> b >> c;
  j = c / b;

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


#include <algorithm>
#include <iostream>
#include <map>
#include <string>
#include <vector>

void d(std::istream &in) {
  unsigned long long A, B, N;
  in >> A >> B >> N;

  const unsigned long long min = std::min(B - 1, N);
  const double x_B = static_cast<double>(min) / B;
  const unsigned long long max =
      static_cast<unsigned long long>(static_cast<double>(A) * x_B) -
      A * static_cast<unsigned long long>(x_B);

  std::cout << max;
}

int main(int, char *[]) {
  d(std::cin);
  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <map>
#include <string>
#include <vector>

void d(std::istream &in) {
  unsigned long long A, B, N;
  in >> A >> B >> N;

  unsigned long long max = 0;
  double maxD = 0;
  for (unsigned long long x = 1; x <= N; ++x) {
    const double x_B = static_cast<double>(x) / B;
    double nD = x_B - static_cast<unsigned long long>(x_B);
    if (maxD < nD)
      maxD = nD;
    if (x == B)
      break;
  }

  max = A * maxD;

  std::cout << max;
}

int main(int, char *[]) {
  d(std::cin);
  return 0;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  long double a, b, n;
  cin >> a >> b >> n;
  // long double max = -1;
  long double x = 0;
  // while(x <= n) {
  //
  //         if(value > max) {
  //                 max = value;
  //         }
  //         x++;
  // }
  if (b - 1 <= n)
    n = b - 1;
  long double value = floor(a * n / b) - (a * floor(n / b));
  cout << value << "\\n";
}


Error: TLE

Fixed submission:

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

int main() {
  long double a, b, n;
  cin >> a >> b >> n;
  long double max = -1;
  long double x = 0;
  while (x <= n) {
    long double value = floor(a * x / b) - (a * floor(x / b));
    if (value > max) {
      max = value;
    }
    x++;
  }
  cout << max << "\\n";
}