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

// </> : towhid1zaman

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define fill(a, b) memset(a, b, sizeof(a))
#define all(v) (v).begin(), (v).end()
#define sp(k) cout << setprecision(k) << fixed;
#define rep(i, a) for (int i = 0; i < a; i++)
#define rep1(i, a, b) for (int i = (a); i <= (b); ++i)
#define irep(i, b, a) for (int i = (b); i >= (a); --i)
#define minv(v) *min_element(all(v))
#define maxv(v) *max_element(all(v))
#define unq(v) sort(all(v)), (v).erase(unique(all(v)), (v).end())
#define _ios                                                                   \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define endl "\\n"
#define sqr(a) ((a) * (a))
#define sz(a) int(a.size())
#define ff first
#define ss second
#define pb push_back

const double pi = acos(-1.0);
const int mod = 1000000007; // (int)1e9+7
const int maxn = 2000100;

int main() {
  _ios;

  ll a, b, n;
  cin >> a >> b >> n;
  ll x = min(b - 1, n);
  cout << a * x / b << endl;
  return 0;
}


Error: TLE

Fixed submission:

// </> : towhid1zaman

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define fill(a, b) memset(a, b, sizeof(a))
#define all(v) (v).begin(), (v).end()
#define sp(k) cout << setprecision(k) << fixed;
#define rep(i, a) for (int i = 0; i < a; i++)
#define rep1(i, a, b) for (int i = (a); i <= (b); ++i)
#define irep(i, b, a) for (int i = (b); i >= (a); --i)
#define minv(v) *min_element(all(v))
#define maxv(v) *max_element(all(v))
#define unq(v) sort(all(v)), (v).erase(unique(all(v)), (v).end())
#define _ios                                                                   \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define endl "\\n"
#define sqr(a) ((a) * (a))
#define sz(a) int(a.size())
#define ff first
#define ss second
#define pb push_back

const double pi = acos(-1.0);
const int mod = 1000000007; // (int)1e9+7
const int maxn = 2000100;
const ll xy = 1e11;
// ll res(ll a,ll b,ll x){
//     return floor((a*x)/b) - a* floor(x/b);
// }
int main() {
  _ios;

  ll a, b, n;
  cin >> a >> b >> n;
  ll ans = 1e-5, cnt = 0;

  for (ll i = 1; i <= min(n, xy); i++) {
    cnt = floor((a * i) / b) - a * floor(i / b);
    ans = max(cnt, ans);
  }
  cout << ans << endl;
  return 0;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

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

  if (N < B) {
    cout << static_cast<long long>(A * N / B);
  } else {
    cout << static_cast<long long>(A * (B - 1) / B);
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

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

  if (N < B) {
    cout << static_cast<long long>(A * N / B);
    return 0;
  } else {
    for (long long x = 0; x <= N; x++) {
      long long a = (A * x / B);
      long long b = (x / B);
      long long sum = a - A * b;
      if (max < sum) {
        max = sum;
      }
      if (b > 0)
        break;
    }
  }

  cout << max;

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

#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, n) for (int i = a; i <= n; i++)
#define per(i, a, n) for (int i = n - 1; i >= a; i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int, int> PII;
typedef double db;
const ll mod = 998244353;
ll powmod(ll a, ll b) {
  ll res = 1;
  a %= mod;
  assert(b >= 0);
  for (; b; b >>= 1) {
    if (b & 1)
      res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

const int N = 1e5 + 50;
ll s[N];
ll a[N];
int main() {
  ll a, b, n;
  cin >> a >> b >> n;
  if (b > n) {
    cout << floor((1ll) * a * n / b);
  } else {

    cout << floor((1ll) * a * (b - 1) / b);
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, n) for (int i = a; i <= n; i++)
#define per(i, a, n) for (int i = n - 1; i >= a; i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int, int> PII;
typedef double db;
const ll mod = 998244353;
ll powmod(ll a, ll b) {
  ll res = 1;
  a %= mod;
  assert(b >= 0);
  for (; b; b >>= 1) {
    if (b & 1)
      res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

const int N = 1e5 + 50;
ll s[N];
ll a[N];
int main() {
  ll a, b, n;
  cin >> a >> b >> n;
  if (b > n) {
    cout << floor((1ll) * a * n / b);
  } else {
    ll ans = 0;
    for (int i = b - 1; i <= n; i += b) {
      ans = max(ans, (ll)(floor((1ll) * a * i / b) - a * floor(i / b)));
    }
    ans = max(ans, (ll)(floor((1ll) * a * n / b) - a * floor(n / b)));
    cout << ans;
  }
  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++)

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;
  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++)

typedef long long ll;

int main() {
  ll a, b, n;
  cin >> a >> b >> n;
  ll ans = 0;
  for (int i = 1; i <= n; i++) {
    ll tmp = a * i / b - a * (i / b);
    if (tmp < ans)
      break;
    ans = tmp;
  }

  cout << ans << endl;

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

/* You can't hack me! */
#pragma warning(disable : 4996)
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;
typedef vector<ll> vll;
typedef vector<char> vch;
typedef set<ll> sll;
#define fo(i, n) for (ll i = 0; i < (n); i++)
#define FO(i, a, b) for (auto i = a; i != (b); i += (b) > (a) ? 1 : -1)
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(c) c.begin(), c.end()
#define sc scanf
#define pr printf
#define in(x) sc("%lld", &(x))
#define id(x) sc("%Lf", &(x))
#define os(x) pr("%lld ", x)
#define on(x) pr("%lld\\n", x)
#define nl pr("\\n")
const ll P = 998244353;
const ll N = 200010;

int main() {
  /*ios::sync_with_stdio(false);
  cin.tie(0);*/
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  ll t = 1;
  // cin>>(t);
  while (t--) {
    ll a, b, n;
    in(a);
    in(b);
    in(n);
    ll ans = 0;
    if (n < b)
      ans = floor(a * n / b);
    else
      ans = floor(a * (b - 1) / b);
    on(ans);
  }
  cerr << "Time : " << ((double)clock()) / (double)CLOCKS_PER_SEC << "s\\n";
  return 0;
}

Error: TLE

Fixed submission:

/* You can't hack me! */
#pragma warning(disable : 4996)
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;
typedef vector<ll> vll;
typedef vector<char> vch;
typedef set<ll> sll;
#define fo(i, n) for (ll i = 0; i < (n); i++)
#define FO(i, a, b) for (auto i = a; i != (b); i += (b) > (a) ? 1 : -1)
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(c) c.begin(), c.end()
#define sc scanf
#define pr printf
#define in(x) sc("%lld", &(x))
#define id(x) sc("%Lf", &(x))
#define os(x) pr("%lld ", x)
#define on(x) pr("%lld\\n", x)
#define nl pr("\\n")
const ll P = 998244353;
const ll N = 200010;

int main() {
  /*ios::sync_with_stdio(false);
  cin.tie(0);*/
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  ll t = 1;
  // cin>>(t);
  while (t--) {
    ll a, b, n;
    in(a);
    in(b);
    in(n);
    ll ans = floor(a * n / b) - a * floor(n / b);
    fo(i, n + 1) { ans = max(ans, (ll)(floor(a * i / b) - a * floor(i / b))); }
    on(ans);
    nl;
  }
  cerr << "Time : " << ((double)clock()) / (double)CLOCKS_PER_SEC << "s\\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, mx = 0;
  cin >> a >> b >> n;
  if (b == 1) {
    cout << 0 << endl;
    return 0;
  }
  for (int i = 1; i * b - 1 <= n; i++) {
    long long t = i * b - 1;
    mx = max(mx, (a * t / b) - a * (t / b));
  }
  long long t = n;
  mx = max(mx, (a * t / b) - a * (t / b));
  cout << mx << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

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

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

void Main() {
  double A, B;
  long long N, maxY, tmp;
  cin >> A >> B >> N;
  tmp = B - 1;
  if (N < tmp) {
    tmp = N;
  }
  cout << static_cast<long long>(floor(A * tmp / B) - A * floor(tmp / B))
       << endl;
}

int main() {
  std::cout << std::fixed << std::setprecision(15);
  Main();
}

Error: TLE

Fixed submission:

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

void Main() {
  double A, B;
  long long N, maxY, tmp;
  cin >> A >> B >> N;
  for (long long i = 0; i <= N; i++) {
    tmp = floor(A * i / B) - A * floor(i / B);
    if (i == 0) {
      maxY = tmp;
      continue;
    }
    if (maxY < tmp) {
      maxY = tmp;
    }
  }
  cout << maxY << endl;
}

int main() {
  std::cout << std::fixed << std::setprecision(15);
  Main();
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

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

typedef long long int ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef map<int, int> mii;
typedef vector<char> vc;
typedef vector<bool> vb;
#define endl '\\n'
#define forn(i, n) for (int i = 0; i < n; i++)
#define rforn(i, n) for (int i = n - 1; i >= 0; i--)
#define forne(i, n) for (int i = 1; i <= n; i++)
#define rforne(i, n) for (int i = n; i >= 1; i--)
#define forse(i, s, e) for (int i = s; i < e; i++)
#define rforse(i, s, e) for (int i = e - 1; i >= s; i--)
#define all(x) x.begin(), x.end()
#define sz(x) (ll) x.size()
#define MOD 1000000007
#define F first
#define S second
#define pb push_back
#define in insert
#define mp(a, b) make_pair(a, b)
#define fill(a, x) memset(a, x, sizeof a);
#define trav(a, x) for (auto &a : x)
#define min3(a, b, c) min(min(a, b), c)
#define min4(a, b, c, d) min(min(a, b), min(c, d))
#define max3(a, b, c) max(max(a, b), c)
#define max4(a, b, c, d) max(max(a, b), max(c, d))
#define INF INT_MAX
#ifdef KARAN
#include "../../trace.h"
#else
#define trace(args...)
#endif

ll modpow(ll a, ll b, ll m = MOD) {
  a %= m;
  ll res = 1;
  while (b) {
    if (b & 1)
      res = (res * a) % m;
    a = (a * a) % m;
    b >>= 1;
  }
  return res;
}
ll bpow(ll a, ll b) {
  ll res = 1;
  while (b) {
    if (b & 1)
      res = res * a;
    a = a * a;
    b >>= 1;
  }
  return res;
}
ll modinv(ll a, ll m = MOD) { return modpow(a, m - 2, m); }
void graph(vvi &adj, int m) {
  int x, y;
  forn(i, m) {
    cin >> x >> y;
    adj[--x].pb(--y);
    adj[y].pb(x);
  }
}

void solve() {
  ll a, b, n;
  cin >> a >> b >> n;
  ll elem = min(n, b - 1);
  cout << (a * elem) / b << endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
#ifdef KARAN
  freopen("inp.txt", "r", stdin);
  freopen("out.txt", "w", stdout);
  freopen("err.txt", "w", stderr);
#endif
  int t = 1;
  // cin>>t;
  while (t--)
    solve();
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
long long n, j, i, k, a, b, m1, m2, m3;
long long ma = 1e-9;
int main() {
  scanf("%lld%lld%lld", &a, &b, &n);
  for (i = 1; i <= n; i++) {
    m1 = 1.0 * a * i / b;
    m2 = 1.0 * i / b;
    m3 = (int)m1 - (int)m2 * a;
    if (m3 > ma)
      ma = m3;
  }
  printf("%lld", ma);
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

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

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

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

Error: TLE

Fixed submission:

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

int main() {
  ll A, B, N;
  cin >> A >> B >> N;
  ll s = B / A - 1;
  ll res = 0;
  for (ll i = s; i <= N; i++) {
    ll calc = (A * i / B) - A * (i / B);
    res = max(res, calc);
  }

  cout << res << endl;
}
Problem p02696 (C++) — buggy submission, verdict: Runtime Error

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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

#define big ((ll)(1e9) + 7)

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


Error: 0

Fixed submission:

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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

#define big ((ll)(1e9) + 7)

int main() {
  ll a, b, n;
  cin >> a >> b >> n;
  vector<ull> ans(n);
  for (ll i = 0; i < n; i++) {
    ans[i] = (a * (i + 1)) / b - a * ((i + 1) / b);
  }
  sort(ans.rbegin(), ans.rend());
  cout << ans[0] << 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++)
typedef long long INT;
double PI = 3.14159265;
using namespace std;
using Graph = vector<vector<int>>;
using Field = vector<string>;
using DGraph = vector<vector<pair<int, int>>>;

const long long INF = 1LL << 60;
//---//

int main() {
  INT a, b, n, ans = 0;
  cin >> a >> b >> n;

  if (b - 1 <= n)
    n = max(n % b, b - 1);
  else
    n = n % b;

  ans = (a * n) / b - (n / b) * a;

  cout << ans << endl;

  return 0;
}


Error: TLE

Fixed submission:

#include "bits/stdc++.h"
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long INT;
double PI = 3.14159265;
using namespace std;
using Graph = vector<vector<int>>;
using Field = vector<string>;
using DGraph = vector<vector<pair<int, int>>>;

const long long INF = 1LL << 60;
//---//

int main() {
  INT a, b, n, ans = 0;
  cin >> a >> b >> n;

  for (int i = 0; i <= b && i <= n; i++) {
    ans = max(ans, (a * i) / b - (i / b) * a);
  }
  cout << ans << endl;

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

#include <bits/stdc++.h>
#define ios ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define debug freopen("in.txt", "r", stdin), freopen("out.txt", "w", stdout);
#define pb push_back
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int maxn = 1e6 + 10;
const int maxM = 1e6 + 10;
const int inf = 0x3f3f3f3f;

ll A, B, N;
int main() {
  // debug;
  ios;

  cin >> A >> B >> N;
  if (N >= B)
    cout << A * (B - 1) / B;
  else
    cout << A * N / B;

  return 0;
}


Error: WA

Fixed submission:

// In the name of God

#include <bits/stdc++.h>

using namespace std;

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

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

  auto calc = [&](long long x) {
    return (a * (x % b) - ((a % b) * x) % b) / b;
  };

  cout << max(calc(min(n, b - 1)), calc(min(n, b / (a % b))));

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

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  ll a, b, n;
  cin >> a >> b >> n;
  ll ans = 0;
  n = min(n, b - 1);

  ll pos = floor(a * n / b);
  ans = max(pos, ans);
  cout << ans;
}


Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

int main() {
  long long int a, b, n, i = 1, k = 0, t;
  cin >> a >> b >> n;
  for (; i <= n; i++) {
    t = (a * i) / b - a * (i / b);
    if (t > k)
      k = t;
  }
  cout << k << endl;
  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, P, a;
  cin >> A >> B >> N;
  ;
  P = min(B - 1, N);
  a = A * P / B;
  cout << a << endl;
}


Error: TLE

Fixed submission:

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

int main() {
  long long int A, B, N;
  cin >> A >> B >> N;
  ;
  long long int a = 0, b, c;

  if (B - 1 <= N) {
    for (long long int i = B - 1; i <= N; i = i + B) {
      b = A * i / B;
      c = i / B;
      c *= A;
      if (b - c > a)
        a = b - c;
    }
  } else
    a = A * N / B;
  cout << a << endl;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int floor(double t) { return int(t); }

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

  cin >> A >> B >> N;

  int maxValue = 0;
  double minx = min(B - 1, N);

  // for(int i=1; i<N+1; i++){
  //     double id = (double)i;
  //     maxValue = max((double)maxValue, floor(A*id/B) - A * floor(id/B) );
  // }
  maxValue = floor(A * minx / B) - A * floor(minx / B);

  cout << (int)maxValue << endl;

  return 0;
}

Error: TLE

Fixed submission:

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

int floor(double t) { return int(t); }

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

  cin >> A >> B >> N;

  int maxValue = 0;

  for (int i = 1; i < N + 1; i++) {
    double id = (double)i;
    maxValue = max((double)maxValue, floor(A * id / B) - A * floor(id / B));
  }

  cout << (int)maxValue << endl;

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

#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
typedef long long ll;
typedef pair<int, int> P;

int main() {
  ll a, b, n, i, res = 0;
  cin >> a >> b >> n;
  i = min(n, b - 1);
  res = max(res, (ll)floor((double)a * (double)i / (double)b) -
                     a * (ll)floor((double)i / (double)b));
  cout << res;

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
typedef long long ll;
typedef pair<int, int> P;

int main() {
  ll a, b, n, res = 0;
  cin >> a >> b >> n;
  for (ll i = b - 1; i <= n; i += b) {
    res = max(res, (ll)floor((double)a * (double)i / (double)b) -
                       a * (ll)floor((double)i / (double)b));
  }
  if (res == 0) {
    res = max(res, (ll)floor((double)a * (double)n / (double)b) -
                       a * (ll)floor((double)n / (double)b));
  }
  cout << res;

  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 rep2(i, x, n) for (int i = x; i < (n); i++)
#define ALL(n) begin(n), end(n)
using namespace std;
using ll = long long;

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

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#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)
using namespace std;
using ll = long long;

int main() {
  ll a;
  ll b, n;
  cin >> a >> b >> n;
  ll ans = 0;
  rep(i, n + 1) {
    ll tmp;
    tmp = floor((double)(a * i) / b) - a * floor((double)i / b);
    ans = max(ans, tmp);
  }
  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;

  long long ans = 0, x = n;
  if (n >= b - 1)
    x = b - 1;
  ans = floor(a * x / b) - a * floor(x / b);

  cout << ans << endl;
}


Error: TLE

Fixed submission:

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

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

  int ans = 0;
  for (double x = 1; x <= n; x++) {
    int g = ans;
    ans = floor(a * x / b) - a * floor(x / b);
    ans = max(ans, g);
  }
  cout << ans << endl;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define ll long long int
#define mod 1000000007
#define se second
#define fi first
#define endl "\\n"
#define pi 3.1415926535897932384626433832795028841971
#define MAX 9223372036854775807
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  //	cout<<fixed<<setprecision(10);
  ll a, b, n;
  cin >> a >> b >> n;
  ll m = (n / b) * b - 1;
  ll ans1 = ((a * m) / b) - a * (m / b);
  ll ans = ((a * n) / b) - a * (n / b);
  cout << max(ans, ans1);
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define ll long long int
#define mod 1000000007
#define se second
#define fi first
#define endl "\\n"
#define pi 3.1415926535897932384626433832795028841971
#define MAX 9223372036854775807
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  //	cout<<fixed<<setprecision(10);
  ll a, b, n;
  cin >> a >> b >> n;
  ll x, y, z;
  x = min(b - 1, n);
  ll ans = 0;
  ll ans1;
  while (x <= n) {
    ans1 = ((a * x) / b) - a * (x / b);
    ans = max(ans, ans1);
    x += 1;
    x += b;
    x -= 1;
  }
  cout << ans;
  return 0;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
int main(void) {
  // Your code here!
  long long A, B, N, X, Y, number, L;
  cin >> A >> B >> N;
  number = 0;
  if (N < B) {
    X = A * N / B;
    Y = N / B;
    number = X - A * Y;
  }
  if (N >= B) {
    X = A * (B - 1) / B;
    Y = 0;
    number = X - A * Y;
  }
  cout << number << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main(void) {
  // Your code here!
  long long A, B, N, X, Y, number;
  cin >> A >> B >> N;
  number = 0;
  for (int i = 1; i <= N; i++) {
    X = A * i / B;
    Y = i / B;
    if (number < X - A * Y) {
      number = X - A * Y;
    }
  }
  cout << number << endl;
  return 0;
}
Problem p02696 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  long long int A, B, N, i, x;
  cin >> A >> B >> N;
  /*//	long long int end = N/(B-1)+1;
          long long int max = (A*N/B) - A*(N/B);

  //	for(i=1; i<=end; i++){
                  x = (B-1)*i;
  //		if(x<=N){
                          int floor = (A*x/B) - A*(x/B);
  //			if(floor > max)	max = floor;
  //		}
  //	}
          if(floor>max)	max = floor;

          cout << max << endl;
  */

  long long int f1 = A * N / B;
  long long int f2 = A * (B - 1) / B;

  cout << min(f1, f2) << endl;

  return 0;
}


Error: 0

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  long long int A, B, N, i, x;
  cin >> A >> B >> N;
  long long int end = N / (B - 1) + 1;
  long long int max = (A * N / B) - A * (N / B);

  for (i = 1; i <= end; i++) {
    x = (B - 1) * i;
    if (x <= N) {
      int floor = (A * x / B) - A * (x / B);
      if (floor > max)
        max = floor;
    }
  }

  cout << max << endl;

  return 0;
}