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

#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;
typedef long long int ll;
void sayYes() { cout << "Yes" << endl; };
void sayNo() { cout << "No" << endl; };
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } // 最大公約数
ll lcm(ll a, ll b) { return a * b / gcd(a, b); };    // 最小公倍数
ll getDigit(ll num) { return log10(num) + 1; }       // 桁数
ll digitSum(ll n) {
  return (n < 10) ? n : digitSum(n / 10) + n % 10;
} // 各桁の和
#define rep(i, n) for (ll i = 0; i < n; i++)

void Main() {
  // int n;
  // cin >> n;
  // vector<int> a(n);
  // rep(i, n)
  // {
  //     cin >> a[i];
  // }
  ll a, b, n;
  cin >> a >> b >> n;
  ll max = 0;

  if (n > b) {
    for (ll x = b - 1; x <= b; ++x) {
      ll v = (ll)(a * x / b) - a * (ll)(x / b);
      max = v > max ? v : max;
    }
  } else {
    for (ll x = n - 1; x <= n; ++x) {
      ll v = (ll)(a * x / b) - a * (ll)(x / b);
      max = v > max ? v : max;
    }
  }

  // for (ll x = 0; x <= n || x <= b + 1; ++x)
  // {
  //     ll v = floor(a * x / b) - a * floor(x / b);
  //     max = v > max ? v : max;
  // }

  cout << max << endl;

  return;
}

signed main(void) {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;
typedef long long int ll;
void sayYes() { cout << "Yes" << endl; };
void sayNo() { cout << "No" << endl; };
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } // 最大公約数
ll lcm(ll a, ll b) { return a * b / gcd(a, b); };    // 最小公倍数
ll getDigit(ll num) { return log10(num) + 1; }       // 桁数
ll digitSum(ll n) {
  return (n < 10) ? n : digitSum(n / 10) + n % 10;
} // 各桁の和
#define rep(i, n) for (ll i = 0; i < n; i++)

void Main() {
  // int n;
  // cin >> n;
  // vector<int> a(n);
  // rep(i, n)
  // {
  //     cin >> a[i];
  // }
  ll a, b, n;
  cin >> a >> b >> n;
  ll max = 0;
  for (ll x = 0; x <= n; ++x) {
    ll v = floor(a * x / b) - a * floor(x / b);
    max = v > max ? v : max;
  }

  cout << max << endl;

  return;
}

signed main(void) {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}
Problem p02696 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 1; i <= (n); ++i)
typedef long long ll;
using namespace std;
const ll MAX = 2500LL;
typedef pair<ll, ll> P;

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

  ll a, b, n;
  cin >> a >> b >> n;
  ll ansa, ansb, ans;
  ansa = (a * n) / b - a * (n / b);
  ll x = (n / b) * b - 1;
  ansb = (a * x) / b - a * (x / b);
  ans = max(ansa, ansb);
  cout << ans << endl;

  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 1; i <= (n); ++i)
typedef long long ll;
using namespace std;
const ll MAX = 2500LL;
typedef pair<ll, ll> P;

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

  vector<ll> sum(n);
  rep(i, n) {
    int q = (a * i) / b - a * (i / b);
    sum.push_back(q);
  }
  // for(auto item : sum){
  //   cout << "edge:" << sum.first << endl;
  // }

  std::vector<ll>::iterator iter = std::max_element(sum.begin(), sum.end());
  size_t index = std::distance(sum.begin(), iter);
  std::cout << sum[index] << std::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 all(x) (x).begin(), (x).end()
using namespace std;
const int INF = 1145141919, MOD = 1e9 + 7;
const int64_t LINF = 8931145141919364364, LMOD = 998244353;
// const int dy[]={0,-1,0,1,1,-1,-1,1};
// const int dx[]={1,0,-1,0,1,1,-1,-1};

int main() {
  int64_t a, b, n;
  cin >> a >> b >> n;
  if (b == 1) {
    cout << 0 << '\\n';
    return 0;
  }
  int64_t t = n / b * b - 1;
  int64_t ans = a * t / b - a * (t / b);
  ans = max(ans, a * n / b - a * (n / b));
  cout << ans << '\\n';
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(), (x).end()
using namespace std;
const int INF = 1145141919, MOD = 1e9 + 7;
const int64_t LINF = 8931145141919364364, LMOD = 998244353;
// const int dy[]={0,-1,0,1,1,-1,-1,1};
// const int dx[]={1,0,-1,0,1,1,-1,-1};

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

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

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

Error: TLE

Fixed submission:

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

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

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


Error: TLE

Fixed submission:

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

#include <iostream>

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

  const double dB = (double)B;
  const double dAB = A / dB;

  unsigned long long x = 0;
  unsigned long long max = 0;
  for (int i = 0; x < N; ++i) {
    x = B * (i + 1) - 1;
    x = x > N ? N : x;

    const unsigned long long result =
        (unsigned long long)(x * dAB) - A * (unsigned long long)(x / dB);

    if (result > max)
      max = result;
    else
      break;
  }

  std::cout << max << std::endl;

  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>

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

  const double dB = (double)B;
  const double dAB = A / dB;

  unsigned long long x = 0;
  unsigned long long max = 0;
  for (int i = 0; x < N; ++i) {
    x = B * (i + 1) - 1;
    x = x > N ? N : x;

    const unsigned long long result =
        (unsigned long long)(x * dAB) - A * (unsigned long long)(x / dB);

    if (result > max)
      max = result;
  }

  std::cout << max << std::endl;

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

#include <algorithm>
#include <cmath>
#include <cstring>
#include <functional>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>

#define roop(i, n) for (int i = 0; i < n; i++)
#define DIV 1000000007

using namespace std;
using ll = long long int;
using ull = unsigned long long;

float myPower(int a, int n) { // aのn乗の計算
  float x = 1;
  while (n > 0) { // 全てのbitが捨てられるまで
    if (n & 1) {  // 一番右のbitが１のとき
      x *= a;
    }
    a *= a;
    n >>= 1; // bit全体を右に1つシフトして一番右を捨てる
  }
  return x;
}

ll combination(ll n, ll r) {
  if (n < 0 || r < 0 || r > n)
    return -1;

  if (n - r < r)
    r = n - r;
  if (r == 0)
    return 1;
  if (r == 1)
    return n;

  vector<ll> num(r);
  vector<ll> den(r);

  for (ll i = 0; i < r; i++) {
    num[i] = n - r + i + 1;
    den[i] = i + 1;
  }

  for (ll p = 2; p <= r; p++) {
    ll pivot = den[p - 1];
    if (pivot > 1) {
      ll offset = (n - r) % p;
      for (ll k = p - 1; k < r; k += p) {
        num[k - offset] /= pivot;
        den[k] /= pivot;
      }
    }
  }
  ll result = 1;
  for (ll k = 0; k < r; k++) {
    if (num[k] > 1)
      result *= num[k];
  }
  return result;
}

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

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstring>
#include <functional>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>

#define roop(i, n) for (int i = 0; i < n; i++)
#define DIV 1000000007

using namespace std;
using ll = long long int;
using ull = unsigned long long;

float myPower(int a, int n) { // aのn乗の計算
  float x = 1;
  while (n > 0) { // 全てのbitが捨てられるまで
    if (n & 1) {  // 一番右のbitが１のとき
      x *= a;
    }
    a *= a;
    n >>= 1; // bit全体を右に1つシフトして一番右を捨てる
  }
  return x;
}

ll combination(ll n, ll r) {
  if (n < 0 || r < 0 || r > n)
    return -1;

  if (n - r < r)
    r = n - r;
  if (r == 0)
    return 1;
  if (r == 1)
    return n;

  vector<ll> num(r);
  vector<ll> den(r);

  for (ll i = 0; i < r; i++) {
    num[i] = n - r + i + 1;
    den[i] = i + 1;
  }

  for (ll p = 2; p <= r; p++) {
    ll pivot = den[p - 1];
    if (pivot > 1) {
      ll offset = (n - r) % p;
      for (ll k = p - 1; k < r; k += p) {
        num[k - offset] /= pivot;
        den[k] /= pivot;
      }
    }
  }
  ll result = 1;
  for (ll k = 0; k < r; k++) {
    if (num[k] > 1)
      result *= num[k];
  }
  return result;
}

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

#include <bits/stdc++.h>
#define rep(i, n) for (int(i) = 0; (i) < (int)(n); (i)++)
#define REP(i, n) for (int(i) = 0; (i) <= (int)(n); (i)++)
#define rep1(i, x, n) for (int(i) = (x); (i) < (int)(n); (i)++)
#define REP1(i, x, n) for (int(i) = (x); (i) <= (int)(n); (i)++)
#define rrep(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
using namespace std;
using ll = long long;
using ull = unsigned long long;
using Int = long long;

// INT_MAX = 2147483647;
// LLONG_MAX = 9223372036854775807;
// ULLONG_MAX = 18446744073709551615;
const int MOD = 1000000007;
const ll INF = numeric_limits<ll>::max();
const int inf = 1e8;
typedef pair<int, int> P;
typedef std::priority_queue<int> IntPrioQueue;
typedef std::priority_queue<int, std::vector<int>, std::greater<int>>
    IntReversePrioQueue;

// 少数点表示
// cout << std::fixed << std::setprecision(14) << 値

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll a, b, n;
  cin >> a >> b >> n;
  ll ans = 0;
  ll i = 0, j = b;
  bool flag;
  if (n < b) {
    ans = floor(((double)a * n) / b) - a * floor((double)n / b);
    cout << ans << endl;
    return 0;
  } else {
    ans = floor(((double)a * (b - 1)) / b) - a * floor((double)(b - 1) / b);
    cout << ans << endl;
    return 0;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int(i) = 0; (i) < (int)(n); (i)++)
#define REP(i, n) for (int(i) = 0; (i) <= (int)(n); (i)++)
#define rep1(i, x, n) for (int(i) = (x); (i) < (int)(n); (i)++)
#define REP1(i, x, n) for (int(i) = (x); (i) <= (int)(n); (i)++)
#define rrep(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
using namespace std;
using ll = long long;
using ull = unsigned long long;
using Int = long long;

// INT_MAX = 2147483647;
// LLONG_MAX = 9223372036854775807;
// ULLONG_MAX = 18446744073709551615;
const int MOD = 1000000007;
const ll INF = numeric_limits<ll>::max();
const int inf = 1e8;
typedef pair<int, int> P;
typedef std::priority_queue<int> IntPrioQueue;
typedef std::priority_queue<int, std::vector<int>, std::greater<int>>
    IntReversePrioQueue;

// 少数点表示
// cout << std::fixed << std::setprecision(14) << 値

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll a, b, n;
  cin >> a >> b >> n;
  ll ans = 0;
  ll i = 1;
  ll bef, zeroc = 0;
  while (i <= n) {
    ll fl = floor(((double)a * i) / b) - a * floor((double)i / b);
    // cout << fl <<" "<< i << endl;
    if (ans <= fl) {
      ans = fl;
    } else {
      break;
    }
    i++;
  }

  cout << ans << endl;

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

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

ll D(ll A, ll B, ll x) { return floor((A * x) / B) - (A * floor(x / B)); }

int main() {

  ll A, B, N, MAX = 0, result = 0;
  cin >> A >> B >> N;

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

Error: TLE

Fixed submission:

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

int main() {

  ll A, B, N, MAX = 0, result = 0;
  cin >> A >> B >> N;

  // for(ll x=0;x<=N;x++){
  // // if(A*x < B || x >= B){
  // // continue;
  // // }
  // result=floor((A*x)/B)-(A*floor(x/B));
  // if(result > MAX){
  // MAX = result;
  // }
  // }

  for (ll x = N / 2; x <= N; x++) {
    if (A * x < B || x >= B) {
      continue;
    }
    result = floor((A * x) / B);
    if (result > MAX) {
      MAX = result;
    }
  }

  cout << MAX << endl;
}
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 = 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;
using ll = long long;

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

  ll ans = 0;
  for (ll x = 0; x <= n; x++) {
    if (x % b == 0)
      continue;
    ll l = (a * x) / b;
    ll r = a * (x / b);
    ans = max(ans, l - r);
  }

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

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

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

Error: TLE

Fixed submission:

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

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

#include <bits/stdc++.h>

using namespace std;

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

  long long int x = min(B - 1, N);
  cout << (A * x) / B - A * (x / B);
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define set0(a) memset((a), 0, sizeof(a))
#define set1(a) memset((a), -1, sizeof(a))
#define pi pair<int, int>
#define ps pair<string, string>
#define pl pair<long, long>
#define pll pair<long long, long long>
#define vll vector<long long>
#define vl vector<long>
#define vi vector<int>
#define vs vector<string>
#define vps vector<ps>
#define vpi vector<pi>
#define vpl vector<pl>
#define vpll vector<pll>
#define flash                                                                  \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);
#define tc(t, T) for (long long t = 0; t < T; t++)
#define rep(i, s, n, d) for (long long i = s; i < n; i = i + d)

bool sortbysec(const pll &a, const pll &b) { return (a.second < b.second); }
/*bool cxp pair<ll, pll> &a,
              const pair<ll, pll> &b)
{
    return (a.ff < b.ff);
}*/

void func(void) {
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
}
ll gcd(ll a, ll b) {
  if (b == 0)
    return a;
  else
    gcd(b, a % b);
}
void printStack(stack<string> s) {
  if (s.empty())
    return;

  string x = s.top();
  s.pop();
  printStack(s);
  cout << x;
  s.push(x);
}

int main() {

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

  ll left = 1;
  ll right = min(b, n);
  ll mid = 1;
  ll min1 = 0;
  ll max1 = 0;
  ll x = 1;

  while (right - left >= 5) {
    mid = (right + left) / 2;
    ll d = (a * mid) / b - a * (mid / b);
    // cout<<d<<endl;
    if (d > max1) {
      max1 = d;
      x = mid;
      left = mid;
    } else
      right = mid;
  }
  for (int i = left; i <= right; i++) {
    ll d = (a * i) / b - a * (i / b);
    if (d > max1) {
      max1 = d;
      x = i;
    }
  }
  cout << max1 << endl;
}

// 1 2 3 1 5 3 1 0 1 0 2
// 1 2 3 4 5 6 7 8 9 10 11
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

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

long long a, b, n;

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


Error: TLE

Fixed submission:

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

long long a, b, n;

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

#include <bits/stdc++.h>
#define endl '\\n'
#define ll long long
#define ld long double
#define ff first
#define ss second

using namespace std;

ll calc(ll a, ll b, ll n) {
  ll x = n >= b ? b - 1 : n;
  ll max = 0;

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

  return max;
}

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

  cin >> a >> b >> n;

  cout << calc(a, b, n) << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define endl '\\n'
#define ll long long
#define ld long double
#define ff first
#define ss second

using namespace std;

ll calc(ll a, ll b, ll n) {
  ll x = n >= b ? b - 1 : n;
  ll calc, max = 0;

  while (x >= 0) {
    calc = floor((a * x) / b) - a * floor(x / b);

    // cout << calc << endl;
    // cout << floor((a*x) / b) << endl;
    // cout << a * floor(x/b) << endl << endl;

    if (max < calc)
      max = calc;

    x--;
  }

  return max;
}

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

  cin >> a >> b >> n;

  cout << calc(a, b, n) << endl;

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


#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
#define ll long long
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
using namespace std;

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

Error: TLE

Fixed submission:


#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
#define ll long long
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
using namespace std;

int main() {
  ll A, B, N;
  ll ans = 0;
  cin >> A >> B >> N;
  if (A < 100000) {
    for (ll x = 1; x <= N; x++) {
      ll floor1;
      ll floor2;
      ll now;
      floor1 = (A * x) / B;
      floor2 = x / B;
      now = floor1 - A * floor2;
      ans = max(ans, now);
    }
  } else {
    for (ll x = N; x >= 1000000; x--) {
      ll floor1;
      ll floor2;
      ll now;
      floor1 = (A * x) / B;
      floor2 = x / B;
      now = floor1 - A * floor2;
      ans = max(ans, now);
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {

  l1 a, b, n;
  cin >> a >> b >> n;
  l1 ans = 0;
  l1 i = min(b - 1, n);
  l1 x = a * i / b;
  l1 y = i / b;
  ans = x - a * y;

  cout << ans;
  return 0;
}

Error: TLE

Fixed submission:

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

int main() {

  l1 a, b, n;
  cin >> a >> b >> n;
  l1 ans = 0;

  for (l1 i = 0; i < n; i++) {
    l1 x = a * (i + 1) / b;
    l1 y = (i + 1) / b;
    l1 k = x - a * y;
    if (ans < k)
      ans = k;
  }

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

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;

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

  if (n < b) {
    cout << a * n / b << endl;
  } else {
    cout << a * (b - 1) / b << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;

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

  int max = 0;
  for (int x = 0; x <= b; x++) {
    int y = x % b;
    if (y > max) {
      max = y;
    }
    if (x == n) {
      break;
    }
  }

  cout << a * max / b << endl;

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

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

#define int long long
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 rep(i, n) for (int i = 0; i < (int)n; i++)
#define ll long long
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define COUT(x) cout << x << endl;
#define PB(x) push_back(x)
#define MP make_pair
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int INF = 1e9;
const int MOD = 1e9 + 7;

signed main() {
  int a, b, n;
  cin >> a >> b >> n;
  int max = 0;
  /*
  for(int i=n; i>=n-b&&i>0; i--){
      if(max<floor(a*i/b)-a*floor(i/b)){
          max=floor(a*i/b)-a*floor(i/b);
      }
  }
  */
  int x = min(n, b - 1);
  cout << floor(a * x / b) - a * floor(x / b) << endl;
  // cout<<max<<endl;
}

Error: TLE

Fixed submission:

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

#define int long long
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 rep(i, n) for (int i = 0; i < (int)n; i++)
#define ll long long
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define COUT(x) cout << x << endl;
#define PB(x) push_back(x)
#define MP make_pair
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int INF = 1e9;
const int MOD = 1e9 + 7;

signed main() {
  int a, b, n;
  cin >> a >> b >> n;
  int max = 0;
  for (int i = n; i >= n - b && i > 0; i--) {
    if (max < floor(a * i / b) - a * floor(i / b)) {
      max = floor(a * i / b) - a * floor(i / b);
    }
  }
  cout << max << endl;
}