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

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

int s[20];
int a[55], b[55], c[55], d[55];
int sum = -inf;
int n, m, q;

void check() {
  int no = 0;
  for (int i = 0; i < q; i++) {
    if (s[b[i]] - s[a[i]] == c[i]) {
      no += d[i];
    }
  }
  sum = max(sum, no);
  return;
}

void dfs(int now, int val) {
  s[now] = val;
  if (now == n) {
    check();
    return;
  }
  for (int i = val; i <= m; i++) {
    dfs(now + 1, i);
  }
}

int main() {
  cin >> n >> m >> q;
  for (int i = 0; i < q; i++) {
    cin >> a[i] >> b[i] >> c[i] >> d[i];
  }
  dfs(1, 1);
  cout << sum << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stdio.h>
#include <vector>
#define ll long long
#define IO                                                                     \\
  ios::sync_with_stdio(false);                                                 \\
  cin.tie();                                                                   \\
  cout.tie(0)
using namespace std;
int p[20];
int a[51], b[51], c[51], d[51];
int sum = -10000;
int n, m, q;
void choc() {
  int x = 0;
  for (int i = 0; i < q; i++) {
    if (p[b[i]] - p[a[i]] == c[i]) {
      x += d[i];
    }
  }
  sum = max(sum, x);
  return;
}
int dfs(int now, int s) {
  p[now] = s;
  if (now == n) {
    choc();
    return 0;
  }
  for (int i = s; i <= m; i++) {
    dfs(now + 1, i);
  }
}
int main() {
  cin >> n >> m >> q;
  for (int i = 0; i < q; i++) {
    cin >> a[i] >> b[i] >> c[i] >> d[i];
  }
  dfs(1, 1);
  cout << sum << endl;
  return 0;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>
#define mp make_pair
#define pb push_back
#define mem(i, a) memset(i, a, sizeof(i))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
const int DMAX = 1000000 + 5;
const int MOD = 1000000000 + 7;
template <class T> inline void read(T &x) {
  x = 0;
  T f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') {
      f = -1;
    }
    ch = getchar();
  }
  while (ch <= '9' && ch >= '0') {
    x = x * 10 + (ch - '0');
    ch = getchar();
  }
  x *= f;
}
ll a, b, n;
ll x;
int main() {
  read(a), read(b);
  read(n);
  if (n < b) {
    x = n;
  } else {
    x = b - 1;
  }
  cout << floor((db)a * (db(x) / b - floor(db(x) / b))) << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>
#define mp make_pair
#define pb push_back
#define mem(i, a) memset(i, a, sizeof(i))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
const int DMAX = 1000000 + 5;
const int MOD = 1000000000 + 7;
template <class T> inline void read(T &x) {
  x = 0;
  T f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') {
      f = -1;
    }
    ch = getchar();
  }
  while (ch <= '9' && ch >= '0') {
    x = x * 10 + (ch - '0');
    ch = getchar();
  }
  x *= f;
}
ll a, b, n;
ll ans = -100000007;
int main() {
  read(a), read(b), read(n);
  for (int i = sqrt(n); i <= n; i++) {
    ll p = a * (i / b);
    ll cnt = i * a / b - p;
    if (ans < cnt) {
      ans = cnt;
    }
  }
  printf("%lld\\n", ans);
  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;
  if (b <= n) {
    if (a >= b) {
      long long g = n / b;
      long long d = (a * (g * b - 1)) / b - a * (g - 1);

      cout << d << endl;
    } else {
      cout << a - 1 << endl;
    }
  } else {
    cout << a * n / b << 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 c = 0, e = 0;
  if (b <= n) {
    if (a >= b) {
      for (long long x = b - 1; x <= n; x += b) {
        long long d = (a * x / b) - a * e;
        e++;
        if (d > c) {
          c = d;
        }
      }
      cout << c << endl;
    } else {
      cout << a - 1 << endl;
    }
  } else {
    cout << a * n / b << endl;
  }
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

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

#define faster                                                                 \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0);

#define PI acos(-1.0)
#define nl '\\n'

typedef long long int ll;
typedef unsigned long long int llu;

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


Error: TLE

Fixed submission:

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

#define faster                                                                 \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0);

#define PI acos(-1.0)
#define nl '\\n'

typedef long long int ll;
typedef unsigned long long int llu;

int main() {
  faster long double a, b, n, mx = 0, ans;
  cin >> a >> b >> n;
  for (int i = 1; i <= n; i++) {
    ans = floor((a * i) / b) - a * floor(i / b);
    if (ans > mx)
      mx = ans;
  }
  cout << mx << nl;
  return 0;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  long int a, b, n;
  cin >> a >> b >> n;
  if (n < b) {
    cout << (a * n) / b << '\\n';
  } else {
    cout << (a * (b - 1)) / b << '\\n';
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  long int a, b, n, i, temp = 0;
  cin >> a >> b >> n;
  for (i = 1; i <= n; i++) {
    long int temp2 = (a * i) / b - a * (i / b);
    if (temp <= temp2)
      temp = temp2;
    else
      break;
  }
  cout << temp << '\\n';
  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 inf 1000000000
typedef long long ll;

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

  ll x = min(b - 1, n);
  ll ans = a * x / b - a * (x / b);

  cout << ans << endl;

  return 0;
}

Error: TLE

Fixed submission:

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

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

  ll m = 0;

  for (int i = 1; i <= n; i++) {
    ll h = a * i / b - a * (i / b);
    m = max(m, h);
    if (m > h) {
      break;
    }
  }

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

#include <bits/stdc++.h>

long long int a;
long long int b;
long long int n;
using namespace std;

int main() {
  cin >> a;
  cin >> b;
  cin >> n;
  long long int m = 0;
  /*
  for(long long int x=0;x<=n;x++){
      long long int t=((a*x)/b)-a*(x/b);
      if(t>m){
          m=t;
      }
  }*/
  if (b <= n) {
    long long int x = b - 1;
    cout << ((a * x) / b) - a * (x / b);
  } else {
    long long int x = n;
    cout << ((a * x) / b) - a * (x / b);
    /*
    for (long long int i = 0; x < n; i++)
    {
        x = b * n - 1;
        if (x > n)
        {
            break;
        }
        long long int t = ((a * x) / b) - a * (x / b);
        if (t > m)
        {
            m = t;
        }
    }*/
  }
  return 0;
  long long int x = 0;
  for (long long int i = 0; x < n; i++) {
    x = b * n - 1;
    if (x > n) {
      break;
    }
    long long int t = ((a * x) / b) - a * (x / b);
    if (t > m) {
      m = t;
    }
  }
  cout << m;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

long long int a;
long long int b;
long long int n;
using namespace std;

int main() {
  cin >> a;
  cin >> b;
  cin >> n;
  long long int m = 0;
  for (long long int x = 0; x <= n; x++) {
    long long int t = ((a * x) / b) - a * (x / b);
    if (t > m) {
      m = t;
    }
  }
  cout << m;
}
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 < (int)(n); i++)
typedef long long ll;
int main() {
  ll a, b, n;
  cin >> a >> b >> n;
  ll ans = 0;
  if (b - 1 <= n)
    cout << a * (b - 1) / b << endl;
  else {
    cout << a * n / b << endl;
  }
}


Error: TLE

Fixed submission:

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

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

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

  if (n >= (b - 1))
    x = b - 1;
  int ans;
  ans = a * x / b - a * (x / b);
  cout << ans << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main(void) {
  // Your code here!
  long long a, b, n;
  cin >> a >> b >> n;
  long long fMax = 0;

  for (long long i = 0; i <= n; i++) {
    long long tmp = ((a * i) / b) - (a * (i / b));
    fMax = max(fMax, tmp);
  }
  cout << fMax << endl;
}
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 < (int)(n); i++)

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

Error: TLE

Fixed submission:

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

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

#include <algorithm>
#include <climits>
#include <iostream>
#include <map>
#include <queue>
#include <vector>
using namespace std;

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

#define INF INT_MAX / 3
#define REP(i, n) for (int i = 0; i < n; i++)

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

  ll answer = 0;
  if (N >= B - 1) {
    answer = (A * (B - 1)) / B;
  } else {
    answer = (A * N) / B;
  }
  cout << answer << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <climits>
#include <iostream>
#include <map>
#include <queue>
#include <vector>
using namespace std;

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

#define INF INT_MAX / 3
#define REP(i, n) for (int i = 0; i < n; i++)

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

  ll answer = 0;
  for (ll i = 1; i <= N; i++) {
    answer = max((A * i) / B - A * (i / B), answer);
  }
  cout << answer << endl;
  return 0;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#include "bits/stdc++.h"
#include <math.h>
#include <time.h>
using namespace std;
const long long mod = 1000000007;
#define ll long long
#define P pair<int, int>
#define dump(x)                                                                \\
  if (dbg) {                                                                   \\
    cout << #x << " = " << (x) << endl;                                        \\
  }
bool dbg = false;
long long gcd(long long a, long long b) {
  if (a % b == 0) {
    return (b);
  } else {
    return (gcd(b, a % b));
  }
}
long long lcm(long long a, long long b) { return (a / gcd(a, b)) * b; }
//---------------------------------------------------------------------------------------------------
/*ここからいじる*/
//---------------------------------------------------------------------------------------------------

void solve() {}
int main() {
  ll a, b, n;
  cin >> a >> b >> n;
  ll memo;
  memo = min(b - 1, n);
  memo = floor(a * memo / b) - a * floor(memo / b);
  cout << memo << endl;
  solve();
  return 0;
}


Error: TLE

Fixed submission:

#include "bits/stdc++.h"
#include <math.h>
#include <time.h>
using namespace std;
const long long mod = 1000000007;
#define ll long long
#define P pair<int, int>
#define dump(x)                                                                \\
  if (dbg) {                                                                   \\
    cout << #x << " = " << (x) << endl;                                        \\
  }
bool dbg = false;
long long gcd(long long a, long long b) {
  if (a % b == 0) {
    return (b);
  } else {
    return (gcd(b, a % b));
  }
}
long long lcm(long long a, long long b) { return (a / gcd(a, b)) * b; }
//---------------------------------------------------------------------------------------------------
/*ここからいじる*/
//---------------------------------------------------------------------------------------------------

void solve() {}
int main() {
  ll a, b, n;
  cin >> a >> b >> n;
  int memo = 0;
  ll i = b - 1;
  if (n <= 100000000) {
    for (int i = 1; i <= n; i++) {
      memo = max(memo, int(floor(a * i / b) - a * floor(i / b)));
    }
  } else if (n < b) {
    memo = max(memo, int(floor(a * n / b) - a * floor(n / b)));
  } else {
    while (n >= i) {
      memo = max(memo, int(floor(a * i / b) - a * floor(i / b)));
      i += b;
    }
  }
  cout << memo << endl;
  solve();
  return 0;
}
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 REP0(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define RREP0(i, n) for (int i = (n)-1; i >= 0; --i)
#define REP1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define RREP1(i, n) for (int i = (n); i >= 1; --i)
#define pow10(n) int(1e##n + n)

typedef long long LL;
typedef pair<int, int> P;

const int INTINF = int(1e9) + 1;
const LL LLINF = LL(1e18) + 1;
long double eps = 1.0E-14;

void solve() {
  LL A, B, N;
  cin >> A >> B >> N;
  LL x = min(N, B - 1);
  LL ans = (A * x) / B - A * (x / B);

  std::cout << ans << endl;
}

int main(int argc, char const *argv[]) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(20);
  solve();
  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 REP0(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define RREP0(i, n) for (int i = (n)-1; i >= 0; --i)
#define REP1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define RREP1(i, n) for (int i = (n); i >= 1; --i)
#define pow10(n) int(1e##n + n)

typedef long long LL;
typedef pair<int, int> P;

const int INTINF = int(1e9) + 1;
const LL LLINF = LL(1e18) + 1;
long double eps = 1.0E-14;

void solve() {
  LL A, B, N;
  cin >> A >> B >> N;
  LL ans = 0;
  LL AmB = A % B;
  for (int x = 1; x <= min(N, B - 1); x++) {
    ans = max(ans, (A * x - (x * AmB) % B) / B);
  }
  std::cout << ans << endl;
}

int main(int argc, char const *argv[]) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(20);
  solve();
  return 0;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

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

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

  if (N >= B) {
    a = A * (B - 1) / B;
    b = (B - 1) / B;
    L = a - A * b;
  }

  else {
    a = A * N / B;
    b = N / B;
    L = a - A * b;
  }

  cout << L << endl;
  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  long A, B, N, a, b, K, L, x;
  cin >> A >> B >> N;
  L = -1000000000000;

  for (x = 0; x < N + 1; x++) {
    a = A * x / B;
    b = x / B;
    K = a - A * b;
    L = max(K, L);
  }

  cout << L << endl;
  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++)
using P = pair<int, int>;
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
const long long INF = 1LL << 60;
const int mod = 1000000007;
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};

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

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++)
using P = pair<int, int>;
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
const long long INF = 1LL << 60;
const int mod = 1000000007;
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};

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

#include <iostream>

using namespace std;

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

  unsigned long i = B - 1;
  if (B > N) {
    i = N;
  }
  unsigned long R = (long)(((A * i) / B) - A * ((long)i / B));
  cout << R << '\\n';
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <math.h>

using namespace std;

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

  long S = 0;
  for (long i = N; i >= 0; --i) {
    // int a = (A*i)/B;
    // int b = A * (i/B);
    // int c = a-b;

    long R = (long)(((A * i) / B) - A * ((long)i / B));
    S = max(R, S);

    if (S > 0 && R == 0) {
      break;
    }
    // cout << "x: " << i << " a: " << a << " b: " << b << " c: " << c << '\\n';
  }
  cout << S << '\\n';
  return 0;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define pb push_back
#define boostup                                                                \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
typedef long long int ll;
using namespace std;
int main() {
  ll a, b, n;
  cin >> a >> b >> n;
  ll ans = -10000000000000;
  ll x = min(n, b - 1);
  ll d;
  d = floor((a * x) / b) - a * floor(x / b);
  cout << d << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define pb push_back
#define boostup                                                                \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
typedef long long int ll;
using namespace std;
int main() {
  ll a, b, n;
  cin >> a >> b >> n;
  ll ans = 0;
  ll x = 0;
  for (x = 0; x <= n; x++) {
    ll d;
    d = floor((a * x) / b) - a * floor(x / b);
    if (d > ans) {
      ans = d;
    }
  }
  cout << ans << endl;
}
Problem p02696 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <vector>
using ll = long long;
using namespace std;

void solve() {}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);

  ll a;
  ll b, n;
  cin >> a >> b >> n;
  // ll k=n/(b-1);
  // ll q=n;
  // ll a1= (a*q)/b;
  // ll a2 = q/b;
  // ll a3 = a*a2;
  // ll ans1= a1-a3;
  ll q, a1, a2, a3, ans1;

  if (n < b - 1) {
    q = n;
    a1 = (a * q) / b;
    a2 = q / b;
    a3 = a * a2;
    ans1 = a1 - a3;

  } else {
    q = b - 1;
    a1 = (a * q) / b;
    a2 = q / b;
    a3 = a * a2;
    ans1 = a1 - a3;
  }
  cout << ans1;
  // if (k==0){
  //     cout << ans1;
  // }
  // else{
  //     for (ll i=1;i<=k;i++){
  //         q=b*i-1;
  //         a1= a*q/b;
  //         a2 = q/b;
  //         a3 = a*a2;

  //         ll ans= a1-a3;

  //         ans1 = max(ans1,ans);

  //     }
  //     cout << ans1;

  return 0;
}

Error: WA

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <vector>
using ll = long long;
using namespace std;

void solve() {}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);

  ll a;
  ll b, n;
  cin >> a >> b >> n;
  ll k = n / (b - 1);
  ll q = n;
  ll a1 = (a * q) / b;
  ll a2 = q / b;
  ll a3 = a * a2;
  ll ans1 = a1 - a3;
  if (k == 0) {
    cout << ans1;
  } else {
    for (ll i = 1; i <= k; i++) {
      q = b * i - 1;
      a1 = a * q / b;
      a2 = q / b;
      a3 = a * a2;

      ll ans = a1 - a3;

      ans1 = max(ans1, ans);
    }
    cout << ans1;
  }

  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, c, n, i, m = 0, d;
  cin >> a >> b >> n;
  m = min(b - 1, n);
  d = (a * m) / b - (a * (m / b));
  cout << d << endl;
}


Error: TLE

Fixed submission:

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

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

typedef long long int ll;
// ll arr[1000000];

int main() {
  ll a, b, n;
  scanf("%lld %lld %lld", &a, &b, &n);
  ll max = 0, ans = 0;
  /*	for(ll i=b;i>=n-b;i--)
          {
                  ans=(a*i)/b - a*(i/b);
                  if(max<ans)
                          max=ans;
          }
          printf("%lld\\n",max);*/
  if (n >= b)
    printf("%lld\\n", (a * (b - 1)) / b);
  else
    printf("%lld\\n", (a * n) / b);
}


Error: TLE

Fixed submission:

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

typedef long long int ll;
// ll arr[1000000];

int main() {
  ll a, b, n;
  scanf("%lld %lld %lld", &a, &b, &n);
  //	ll j=0;
  ll max = 0, ans = 0;
  for (ll i = n; i >= n - b; i--) {
    ans = (a * i) / b - a * (i / b);
    //		arr[j]=(a*i)/b - a*(i/b);
    //		j++;
    if (max < ans)
      max = ans;
  }
  //	sort(arr,arr+1000000);
  //	printf("%lld\\n",arr[999999]);
  printf("%lld\\n", max);
}