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

#include <algorithm>
#include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <stdio.h>
#include <string>
#include <vector>

using namespace std;

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

  // cout<<ans;
  if (n < b - 1)
    cout << floor(a * (n) / b) - a * floor((n) / b);
  else
    cout << floor(a * (b - 1) / b) - a * floor((b - 1) / b);

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <stdio.h>
#include <string>
#include <vector>

using namespace std;

int main() {
  long int a, b, n;
  cin >> a >> b >> n;
  long int ans = -10000000000;
  for (int x = 0; x <= n; x++) {
    long int tmp = a * x;
    long int tmp2 = x / b;
    long int tmp3 = tmp / b - a * tmp2;
    if (tmp3 > ans) {
      ans = tmp3;
    }
  }

  cout << ans;

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

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

int main() {
  ll A, B, N;
  std::cin >> A >> B >> N;

  ll ans = -1;

  if (N >= (B - 1)) {
    ll a = floor((double)(A * (B - 1)) / B);
    ll b = A * floor((double)(B - 1) / B);
    ans = a - b;
  } else {
    ll a = floor((double)(A * N / B));
    ll b = A * floor((double)(N) / B);
    ans = a - b;
  }

  std::cout << ans << '\\n';
  return 0;
}


Error: TLE

Fixed submission:

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

int main() {
  ll A, B, N;
  std::cin >> A >> B >> N;

  ll ans = -1;
  for (int i = 0; i <= N; i++) {
    ll a = floor((double)(A * i) / B);
    ll b = A * floor((double)(i) / B);
    // printf("%d %d\\n",i,a-b);
    if (ans <= a - b) {
      ans = a - b;
    } else
      break;
  }
  std::cout << ans << '\\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 = B - 1;
  if (B - 1 >= N) {
    cout << (A * N) / B - (N / B) * A << endl;
    return 0;
  }
  cout << (A * x) / B - (x / B) * A << 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 x = B - 1, ans = 0;
  if (B - 1 >= N) {
    cout << (A * N) / B - (N / B) * A << endl;
    return 0;
  }
  while (x <= N) {
    ans = max(ans, (A * x) / B - (x / B) * A);
    if (x == N)
      break;
    if (B - 1 >= N - x)
      x = N;
    else
      x += B;
  }
  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, x, y, z, b, n;
  cin >> a >> b >> n;

  x = ((a * (b - 1)) / b) - (a * ((b - 1) / b));
  y = ((a * n) / b) - (a * (n / b));

  if (n >= b - 1)
    cout << x;
  else
    cout << y;

  return 0;
}


Error: TLE

Fixed submission:

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

int main() {
  ll a, x, y, z, b, n, i, m = -1;
  cin >> a >> b >> n;

  for (i = 1; i <= n; i++) {
    x = (a * i) / b;
    y = a * (i / b);
    z = x - y;
    m = max(m, z);
  }

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

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

typedef long long int ll;
typedef pair<ll, ll> p_ll;
typedef vector<pair<ll, ll>>
    vec_p; // vector<pair<ll, ll>> pairs(n) ,pairs.at(i) = make_pair(i*i, i)

#define ture ture
#define flase false
#define falg flag

#define REP(i, x) for (ll i = 0; i < (ll)(x); i++)
#define REPS(i, x) for (ll i = 1; i <= (ll)(x); i++)
#define RREP(i, x) for (ll i = ((ll)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (ll i = ((ll)(x)); i > 0; i--)
#define all(x) (x).begin(), (x).end()

const ll MOD = pow(10, 9) + 7;
const ll LLINF = pow(2, 61) - 1; // llの最大9*10^18
const int INF = pow(2, 30) - 1;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

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

  ll N, A, B;
  string S;
  cin >> A >> B >> N;
  if (B > N) {
    ll ans = 0;
    /*REPS(i, N)
    {
        ll tmp = (A * i) / B;
        ll tmp1 = i / B;
        //cout << tmp - A * tmp1 << endl;


        ans = max(ans, tmp - A * tmp1);

    }
    cout << ans << endl;*/
    ll tmp = (A * N) / B;
    ll tmp1 = N / B;
    cout << tmp - A * tmp1 << endl;
  }

  else {
    ll tmp = (A * (B - 1)) / B;
    ll tmp1 = (B - 1) / B;

    // cout << "test1" << endl;
    // cout << tmp << " " << tmp1 << endl;

    cout << tmp - A * tmp1 << endl;
  }
}


Error: TLE

Fixed submission:

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

typedef long long int ll;
typedef pair<ll, ll> p_ll;
typedef vector<pair<ll, ll>>
    vec_p; // vector<pair<ll, ll>> pairs(n) ,pairs.at(i) = make_pair(i*i, i)

#define ture ture
#define flase false
#define falg flag

#define REP(i, x) for (ll i = 0; i < (ll)(x); i++)
#define REPS(i, x) for (ll i = 1; i <= (ll)(x); i++)
#define RREP(i, x) for (ll i = ((ll)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (ll i = ((ll)(x)); i > 0; i--)
#define all(x) (x).begin(), (x).end()

const ll MOD = pow(10, 9) + 7;
const ll LLINF = pow(2, 61) - 1; // llの最大9*10^18
const int INF = pow(2, 30) - 1;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

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

  ll N, A, B;
  string S;
  cin >> A >> B >> N;
  if (B >= N) {
    ll ans = 0;
    REPS(i, N) {
      ll tmp = (A * i) / B;
      ll tmp1 = i / B;
      // cout << tmp - A * tmp1 << endl;

      ans = max(ans, tmp - A * tmp1);
    }
    cout << ans << endl;
  }

  else {
    ll tmp = (A * (B - 1)) / B;
    ll tmp1 = (B - 1) / B;

    // cout << "test1" << endl;
    // cout << tmp << " " << tmp1 << endl;

    cout << tmp - A * tmp1 << endl;
  }
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define FORR(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)

#define DEBUG(x) cout << #x << ": " << (x) << endl
#define DEBUG_VEC(v)                                                           \\
  cerr << #v << ": ";                                                          \\
  REP(__i, (v).size()) cerr << ((v)[__i]) << ", ";                             \\
  cerr << endl
#define PRINT(x) cout << x << endl
#define all(x) x.begin(), x.end()
#define MM << " " <<
int main() {
  ll a, b, n;

  cin >> a >> b >> n;

  // floor(ax/b) - a*floor(x/b) を最大化

  //   for (int x = 0; x <= n; x++) {
  //     cout << x << " : " << (a * x / b) << "-" << a * (x / b) << " = "
  //          << (a * x / b) - a * (x / b) << endl;
  //   }

  // A>B 周期A
  // A<B 周期B？
  // 単調増加である
  // BもしくはAを超えない最大の

  ll ans = 0;

  for (ll x = max(0LL, n - 100); x <= n; x++) {
    if (x > n)
      continue;
    ans = max(ans, (a * x / b) - a * (x / b));
  }

  for (ll x = max(0LL, b - 100); x <= b + 10; x++) {
    if (x > n)
      continue;
    ans = max(ans, (a * x / b) - a * (x / b));
  }

  for (ll x = max(0LL, a - 100); x <= a + 10; x++) {
    if (x > n)
      continue;
    ans = max(ans, (a * x / b) - a * (x / b));
  }

  cout << ans << endl;
}


Error: TLE

Fixed submission:

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define FORR(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)

#define DEBUG(x) cout << #x << ": " << (x) << endl
#define DEBUG_VEC(v)                                                           \\
  cerr << #v << ": ";                                                          \\
  REP(__i, (v).size()) cerr << ((v)[__i]) << ", ";                             \\
  cerr << endl
#define PRINT(x) cout << x << endl
#define all(x) x.begin(), x.end()
#define MM << " " <<
int main() {
  ll a, b, n;

  cin >> a >> b >> n;

  // floor(ax/b) - a*floor(x/b) を最大化

  //   for (int x = 0; x <= n; x++) {
  //     cout << x << " : " << (a * x / b) << "-" << a * (x / b) << " = "
  //          << (a * x / b) - a * (x / b) << endl;
  //   }

  // A>B 周期A
  // A<B 周期B？
  // 単調増加である
  // BもしくはAを超えない最大の

  ll ans = 0;

  for (int x = max(0LL, n - 100); x <= n; x++) {
    if (x > n)
      continue;
    ans = max(ans, (a * x / b) - a * (x / b));
  }

  for (int x = max(0LL, b - 100); x <= b; x++) {
    if (x > n)
      continue;
    ans = max(ans, (a * x / b) - a * (x / b));
  }

  for (int x = max(0LL, a - 100); x <= a; x++) {
    if (x > n)
      continue;
    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>
#define inf 0x3f3f3f3f
using namespace std;
typedef long long ll;

int main() {
  ll a, b, n;
  cin >> a >> b >> n;
  ll flag = -inf;

  /*for(ll i=1;i<=n;i++){

     flag = max(res-ans,flag);

  }
  */
  if (n < b) {
    cout << (a * n) / b << endl;
    return 0;
  } else {
    flag = max(a * (b - 1) / b, flag);

    flag = max(flag, (a * n) / b - a * (n / b));
  }
  cout << flag << endl;
  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  ll a, b, n;
  cin >> a >> b >> n;
  ll flag = -inf;

  for (ll i = 1; i <= n; i++) {
    ll res = (a * i) / b;
    ll ans = a * (i / b);
    flag = max(res - ans, flag);
  }
  cout << flag << 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++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main() {
  ll A, B, N;
  cin >> A >> B >> N;
  ll ans = 0;
  ll tmp;
  tmp = min(B - 1, N);
  ans = A * tmp / B - A * (tmp / B);
  cout << ans << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main() {
  ll A, B, N;
  cin >> A >> B >> N;
  ll ans = 0;
  ll tmp;
  for (ll i = 0; i < N + 1; i++) {
    tmp = A * i / B - A * (i / B);
    ans = max(ans, tmp);
  }
  cout << ans << endl;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string.h>
#include <string>
#include <tuple>#include <iostream>
#include <tuple>
#include <vector>
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define REP(i, a, b) for (int i = a; i > b; i--)
#define vint vector<int>
#define vvint vector<vint>
#define CST(x) cout << fixed << setprecision(x) // 小数点以下の桁数指定
#define ct(a) cout << a << endl
static const double pi = 3.141592653589793;
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const int INF = 1e9 + 7;

ll A, B, N;
ll a[51], b[51], c[51], d[51];
ll ans = 0;

int main() {
  cin.tie(0);
  cout.tie(0);
  ios::sync_with_stdio(false);
  cin >> A >> B >> N;

  ll u = min(B - 1, N);
  cout << (A * u) / B << endl;

  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string.h>
#include <string>
#include <tuple>#include <iostream>
#include <tuple>
#include <vector>
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define REP(i, a, b) for (int i = a; i > b; i--)
#define vint vector<int>
#define vvint vector<vint>
#define CST(x) cout << fixed << setprecision(x) // 小数点以下の桁数指定
#define ct(a) cout << a << endl
static const double pi = 3.141592653589793;
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const int INF = 1e9 + 7;

ll A, B, N;
ll a[51], b[51], c[51], d[51];
ll ans = 0;

int main() {
  cin.tie(0);
  cout.tie(0);
  ios::sync_with_stdio(false);
  cin >> A >> B >> N;

  FOR(i, 1, N + 1) {
    if (i % B == 0)
      break;
    ans = max(ans, (A * i) / B);
  }
  cout << ans << endl;

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

#include <cmath>
#include <iostream>
#include <limits>

using namespace std;

int main() {
  long long A, B, N;
  cin >> A >> B >> N;
  long long Y = 0;
  long long Ans = 0;
  if (N >= B)
    Ans = floor(A * (B - 1) / B) - A * floor((B - 1) / B);
  else if (N < B)
    Ans = floor(A * (N) / B) - A * floor(N / B);

  cout << Ans << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <cmath>
#include <iostream>
#include <limits>

using namespace std;

int main() {
  long long A, B, N;
  cin >> A >> B >> N;
  long long Y = 0;
  long long Ans = 0;
  for (int x = 0; x <= N; x++) {
    Y = floor(A * x / B) - A * floor(x / B);
    if (Ans < Y)
      Ans = Y;
  }

  cout << Ans << endl;

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

#include <bits/stdc++.h>
#define div1 1000000007
const long long INF = 1LL << 60;
using namespace std;
typedef long long ll;
typedef long double ld;
// a>b -> a==b;
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
// a<b -> a==b;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int main(void) {
  ll a, b, n, x, ans = 0, num;

  cin >> a >> b >> n;

  num = min(n, b - 1);

  cout << a * num / b - num / b * a << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define div1 1000000007
const long long INF = 1LL << 60;
using namespace std;
typedef long long ll;
typedef long double ld;
// a>b -> a==b;
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
// a<b -> a==b;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int main(void) {
  ll a, b, n, x, ans = 0, p = 0;

  cin >> a >> b >> n;

  for (x = 1; x <= n; x++) {
    if (p > a * x / b - x / b * a)
      break;
    p = a * x / b - x / b * a;
    chmax(ans, a * x / b - x / b * a);
  }

  cout << ans << endl;

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

//
//  main.cpp
//  Study
//
//  Created by 佐々木勇星 on 2020/03/12.
//  Copyright © 2020 佐々木勇星. All rights reserved.
//

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <sstream>
#include <vector>

using namespace std;

long long proba(long long a, long long b, long long k) {
  long long c;
  c = a / k;

  bool flag = false;

  while (1) {
    if (c * k >= a && c * k <= b) {
      // return c * k;
      flag = true;
      break;
    } else if (c * k <= b) {
      c++;
    } else if (c * k > b) {
      break;
    }
  }
  if (flag == true)
    return c;
  else
    return 0;
}

int main(int argc, const char *argv[]) {

  long long a, b, n, max = 0, mn;

  long long ex;

  cin >> a >> b >> n;
  long long ans = 0;

  mn = min(b - 1, n);
  //
  //    for(long long i=0; i<=mn; i++)
  //    {
  //
  //         ans = (long long)(a * i / b) - a * (long long)(i / b);
  //
  //        //cout << ans << endl;
  //        if (ans > max) max = ans;
  //        else if (ans < max) break;
  //    }

  ans = (long long)(a * mn / b) - a * (long long)(mn / b);

  cout << ans << endl;
}


Error: TLE

Fixed submission:

//
//  main.cpp
//  Study
//
//  Created by 佐々木勇星 on 2020/03/12.
//  Copyright © 2020 佐々木勇星. All rights reserved.
//

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <sstream>
#include <vector>

using namespace std;

long long proba(long long a, long long b, long long k) {
  long long c;
  c = a / k;

  bool flag = false;

  while (1) {
    if (c * k >= a && c * k <= b) {
      // return c * k;
      flag = true;
      break;
    } else if (c * k <= b) {
      c++;
    } else if (c * k > b) {
      break;
    }
  }
  if (flag == true)
    return c;
  else
    return 0;
}

int main(int argc, const char *argv[]) {

  long long a, b, n, max = 0, mn;

  long long ex;

  cin >> a >> b >> n;
  long long ans = 0;

  mn = min(b - 1, n);

  for (long long i = 0; i <= mn; i++) {

    ans = (long long)(a * i / b) - a * (long long)(i / b);

    // cout << ans << endl;
    if (ans > max)
      max = ans;
    else if (ans < max)
      break;
  }

  cout << max << endl;
}
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) << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
long long floor1(long long a, long long b, long long x) { return (a * x) / b; }

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

  long long ma = -10000;
  for (long long i = N - 400000000; i <= N; i++) {
    ma = max(ma, floor1(a, b, i) - a * floor1(1, b, i));
  }
  cout << ma << endl;
  return 0;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using std::cin;
using std::cout;
using std::endl;

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

  int64_t n_1 = (n / b) * b;
  //  int64_t n_diff = n - n_1;

  int64_t max = 0;
  /*
    for (int64_t x = 0; x <= n_1; x += b)
    {
      int64_t x_floor = (x - 1) / b;
      int64_t ax_floor = (a * (x - 1)) / b;
      int64_t diff = ax_floor - a * x_floor;
      if (diff > max)
      {
        max = diff;
      }
    }
    */
  int64_t diff_a = (a * (n_1 - 1)) / b - a * ((n_1 - 1) / b);
  int64_t diff_b = (a * n) / b - a * (n / b);
  if (diff_a > diff_b)
    cout << diff_a << endl;
  else
    cout << diff_b << endl;

  //  cout << max << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
using std::cin;
using std::cout;
using std::endl;

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

  int64_t n_1 = (n / b) * b;
  //  int64_t n_diff = n - n_1;

  int64_t max = 0;
  for (int64_t x = 0; x <= n_1; x += b) {
    int64_t x_floor = (x - 1) / b;
    int64_t ax_floor = (a * (x - 1)) / b;
    int64_t diff = ax_floor - a * x_floor;
    if (diff > max) {
      max = diff;
    }
  }

  if ((a * n) / b - a * (n / b) > max)
    max = (a * n) / b - a * (n / b);

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

#include <algorithm>
#include <cmath>
#include <iostream>
#define int long long

signed main() {
  int N, A, B;
  std::cin >> A >> B >> N;
  std::cout << (int)(std::floor((A * std::min((B - 1), N)) / B)) -
                   (int)((A * std::floor(std::min((B - 1), N) / B)));
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#define int long long

signed main() {
  int N, A, B;
  std::cin >> A >> B >> N;
  /*
      int start = 0;
      int end = N + 1;
      int maxVal = 0;
      int moy = 0;

      while (start < end && moy < N)
      {
          moy = (start + end) / 2;
          int val = ((A * moy) / B) - (A * (moy / B));

          if (val > maxVal)
          {
              start = moy;
          }
          else
          {
              end = moy;
          }

          maxVal = std::max(val, maxVal);
      }

      moy = (start + end) / 2;
      int val = (int)(std::floor((A * moy) / B)) - (int)((A * std::floor(moy /
     B))); maxVal = std::max(val, maxVal);*/
  int maxVal = 0;
  for (int i = 0; i <= N; i++) {
    maxVal = std::max(maxVal, (int)(std::floor((A * i) / B)) -
                                  (int)((A * std::floor(i / B))));
  }
  std::cout << maxVal;
}
Problem p02696 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>0
using namespace std;
using ll = long long;

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

Error: -11

Fixed submission:

#include <iostream>
#include <set> // set
#include <vector>
using namespace std;

int main() {
  long long A, B, N;
  cin >> A >> B >> N;
  set<long long> MaX;
  for (int i = B - 1; i <= N; i++) {
    // long long X_1, X_2;
    // X_1 = (long long)(A*i/B);
    // X_2 = A * (long long)(i / B);
    MaX.insert((long long)(A * i / B) - A * (long long)(i / B));
  }

  cout << (long long)*rbegin(MaX) << endl;
}
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 P = pair<int, int>;
using ll = long long;

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

  long double ans = 0;
  if (n < b)
    ans = floor(a * n / b) - a * floor(n / b);
  else
    ans = floor(a * (b - 1) / b) - a * floor((b - 1) / 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 P = pair<int, int>;
using ll = long long;

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

  long double ans = 0;
  rep(x, n + 1) { ans = max(ans, floor(a * x / b) - a * floor(x / b)); }

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

#include <iostream>

using namespace std;

long fl(long a, long b, long x) {
  if (x < 0)
    return 0;
  return (a * x) / b - a * (x / b);
}

int main(void) {

  long a, b, n;
  cin >> a >> b >> n;

  cout << fl(a, b, min(n, b - 1)) << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

int main(void) {

  long a, b, n;
  cin >> a >> b >> n;

  long ans = 0;
  for (long x = 0; x <= n; x++) {
    ans = max(ans, (a * x) / b - a * (x / b));
  }

  cout << ans;

  return 0;
}