alexjercan/bugnet huggingface dataset:
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;

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

  ans = max(ans, (a * n / b) - a * (n / b));
  cout << ans << endl;

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

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

  long long ans = 0;

  long long k = 0;
  while (k * (b - 1) <= n) {
    long long x = k * (b - 1);
    ans = max(ans, (a * x / b) - a * (x / b));
    k++;
  }
  ans = max(ans, (a * n / b) - a * (n / b));
  cout << ans << endl;

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

#include <cmath>
#include <iostream>
using namespace std;
main() {
  long long a, b, n;
  cin >> a >> b >> n;
  if (n < b - 1) {
    cout << a * n / b;
  } else
    cout << a * (b - 1) / b;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
typedef long long ll;
ll a, b, n;
int main() {
  cin >> a >> b >> n;
  ll x = 0;
  for (ll i = n; i >= n - 2 * b; i--) {
    if (i % b > x)
      x = i % b;
  }
  cout << (a * x) / b - a * (x / b) << endl;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <math.h>
#include <queue>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

ll A, B, N;

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


Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <math.h>
#include <queue>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

ll A, B, N;

int main(void) {
  cin >> A >> B >> N;
  ll ans = 0;
  for (ll k = 0; k <= N; k++) {
    ll aa = (A * k) / B;
    ll ab = k / B;
    ll m = aa - A * ab;
    ans = max(ans, m);
  }
  cout << ans << endl;
}
Problem p02696 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;

typedef long long ll;

const int INF = 1 << 30;
const ll LLINF = 1LL << 60;

int mod = 1000000007;

int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll A, B, N;
  cin >> A >> B >> N;
  // A*x/B - x/B の最大値は?
  // xが大きい方がよさそぅ
  if (B == 1)
    cout << 0 << endl;
  else if (B - 1 > N)
    cout << A * N / B - A * (N / B) << endl;
  else {
    ll ok = (N + 1) / B;
    ll x = ok * B - 1;
    cout << A * x / B - A * (x / B) << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;

typedef long long ll;

const int INF = 1 << 30;
const ll LLINF = 1LL << 60;

int mod = 1000000007;

int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll A, B, N;
  cin >> A >> B >> N;
  // A*x/B - x/B の最大値は?
  // xが大きい方がよさそぅ
  if (B == 1)
    cout << 0 << endl;
  else if (B - 1 > N)
    cout << A * N / B - A * (N / B) << endl;
  else {
    ll ok = 0, ng = 1000000000001;
    ll m = (ok + ng) / 2;
    while (abs(ok - ng) > 1) {
      assert(m * B - 1 >= -1);
      if (m * B - 1 <= N)
        ok = m;
      else
        ng = m;
      m = (ok + ng) / 2;
    }
    ll x = ok * B - 1;
    cout << A * x / B - A * (x / B) << endl;
  }
  return 0;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#include <limits>
#define ll long long
#define F first
#define S second
#define pb push_back
#define oo (1LL << 63 - 1)
#define endl '\\n'
#define si size()
#define all(v) v.begin(), v.end()
#define FASTIO ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define Matrix vector<vector<long long>>

using namespace std;

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};

const long double Pi = acos(-1), e = 2.718;
const int N = 2e5 + 10, mod = 1e9 + 7;

int main() {
  FASTIO
  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>
#include <limits>
#define ll long long
#define F first
#define S second
#define pb push_back
#define oo (1LL << 63 - 1)
#define endl '\\n'
#define si size()
#define all(v) v.begin(), v.end()
#define FASTIO ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define Matrix vector<vector<long long>>

using namespace std;

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};

const long double Pi = acos(-1), e = 2.718;
const int N = 2e5 + 10, mod = 1e9 + 7;

int main() {
  FASTIO
  ll a, b, n;
  cin >> a >> b >> n;
  ll ans = 0;
  ll st = max(0ll, (ll)(n - 2e8 + 5e7));
  for (ll i = st; i <= n; i++) {
    ans = max(ans, (a * i) / b - a * (i / b));
  }
  cout << ans << endl;
  return 0;
}
/**

*/
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

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

long long a, b;
long long f(long long x) {
  long long f1 = a * x / b;
  long long f2 = x / b;
  return f1 - a * f2;
}

int main() {
  long long n;
  cin >> a >> b >> n;
  if (b <= n)
    cout << f(b - 1) << endl;
  else
    cout << f(n) << endl;
}


Error: TLE

Fixed submission:

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

int main() {
  long long a, b, n, mx = -1;
  cin >> a >> b >> n;

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

#include <bits/stdc++.h>
using namespace std;
#define fastio                                                                 \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
#define pb push_back
#define ll long long
#define pii pair<int, int>

ll a, b, n;
ll f(ll x) { return a * x / b - a * (x / b); }

void test_case() {
  cin >> a >> b >> n;
  if (n >= b) {
    cout << f(b - 1);
  } else {
    // n < b
    cout << f(n);
  }
}

int main() {
  fastio
  //    int t;
  //    cin>>t;
  //    while(t--)
  test_case();
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define fastio                                                                 \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
#define pb push_back
#define ll long long
#define pii pair<int, int>

ll a, b, n;
ll f(ll x) { return (a * x) / b - a * (x / b); }

void test_case() {
  cin >> a >> b >> n;
  for (int i = 1; i <= n; i++) {
    if (f(i) > f(i + 1)) {
      cout << f(i);
      return;
    }
  }
  cout << f(n);
}

int main() {
  fastio
  //    int t;
  //    cin>>t;
  //    while(t--)
  test_case();
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <set>

using namespace std;

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

  long z;
  long x = min(b - 1, n);
  z = int(a * x / b) - a * int(x / b);

  cout << z << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <map>

using namespace std;

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

  long max = 0;
  for (int x = 0; x <= n; x++) {
    long y = x / b;
    long z = a * x / b - a * y;
    if (z > max)
      max = z;
  }

  cout << max << endl;

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

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>

template <class T> inline void read(T &x) {
  x = 0;
  int f = 0;
  char ch = getchar();
  while (!isdigit(ch)) {
    f |= ch == '-';
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = (x << 1) + (x << 3) + (ch ^ 48);
    ch = getchar();
  }
  x = f ? -x : x;
  return;
}

typedef long long LL;

LL a, b, n, ans;

int main() {
  read(a), read(b), read(n);
  ans = a * std::min(b - 1, n) / b;
  printf("%lld\\n", ans);
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>

template <class T> inline void read(T &x) {
  x = 0;
  int f = 0;
  char ch = getchar();
  while (!isdigit(ch)) {
    f |= ch == '-';
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = (x << 1) + (x << 3) + (ch ^ 48);
    ch = getchar();
  }
  x = f ? -x : x;
  return;
}

typedef long long LL;

LL a, b, n, ans;

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

int main() {
  read(a), read(b), read(n);
  LL g = gcd(a, b);
  LL lcm = a * b / g;
  for (LL x = 0; x <= n && x <= lcm; ++x) {
    ans = std::max(ans, (LL)(floor(a * x / b) - a * floor(x / b)));
  }
  printf("%lld\\n", 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 < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
int main() {
  ll A, B, N;
  cin >> A >> B >> N;
  ll x = min(N, B - 1);
  cout << floor(A * x / B) - A * floor(x / 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++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
int main() {
  ll A, B, N;
  cin >> A >> B >> N;
  ll mx = 0;
  ll j = N;
  j -= B + 1;
  if (j < 0) {
    j = 1;
  }

  for (ll i = j; i <= N; i++) {
    if (A * i % B == 1 && i % B == B - 1) {
      cout << floor(A * i / B) - A * floor(i / B);
      return 0;
    }
    chmax(mx, (ll)(floor(A * i / B) - A * floor(i / B)));
  }

  cout << mx << 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 ll = long long;
using P = pair<int, int>;

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

  double low = 0;
  // 右側
  double high = n + 1;

  auto f = [&](ll i) { return a * i / b - a * (i / b); };
  int cnt = 10000;
  while (--cnt) {
    double c1 = (low * 2 + high) / 3;
    double c2 = (low + high * 2) / 3;
    if (f(c1) <= f(c2))
      low = c1;
    else
      high = c2;
  }
  cout << fixed << setprecision(20) << f(low) << endl;
  return 0;
}

Error: TLE

Fixed submission:

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

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

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

// https://atcoder.jp/contests/abc165/tasks/abc165_d
// 2020-05-02
#include <algorithm>
#include <array>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <vector>
using namespace std;

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

Error: TLE

Fixed submission:

// https://atcoder.jp/contests/abc165/tasks/abc165_d
// 2020-05-02
#include <algorithm>
#include <array>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <vector>
using namespace std;

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

#include <bits/stdc++.h>
#define inf 0x3f3f3f3f
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef double dd;
const int N = 1e5 + 5;
const dd eps = 1e-8;
const int mod = 1e9 + 7;

ll a, b, n;

ll cal(ll x) { return ((a * x) / b) - a * (x / b); }

int main() {
  ios::sync_with_stdio(false);
  // freopen("input.txt","r",stdin);
  cin >> a >> b >> n;
  if (b > n) {
    cout << cal(n) << endl;
  } else
    cout << cal(b - 1) << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define inf 0x3f3f3f3f
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef double dd;
const int N = 1e7 + 5;
const dd eps = 1e-8;
const int mod = 1e9 + 7;

ll a, b, n;
ll ans, ind;

int main() {
  ios::sync_with_stdio(false);
  // freopen("input.txt","r",stdin);
  cin >> a >> b >> n;
  for (ll i = n; i >= n - ll(n); i--) {
    if (i <= 0)
      break;
    ll now = (a * i) / b - a * (i / b);
    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 ll = long long int;
using ull = unsigned long long int;
#define vll vector<ll>

#define FOR(i, b, e) for (int i = (b); i < (e); ++i)
#define REP(i, e) FOR(i, 0, e)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define REV(v) reverse((v).begin(), (v).end())
#define IN(v) cin >> (v);
#define VIN(v, n) REP(i, n) cin >> v[i];
#define OUT(v) cout << (v) << endl;
#define YN(b) OUT((b) ? "YES" : "NO")
#define Yn(b) OUT((b) ? "Yes" : "No")
#define yn(b) OUT((b) ? "yes" : "no")

const ll MOD = 1000000007;

ll f(ll a, ll b, ll x) {
  return floor(a * x / (double)b) - a * floor(x / (double)b);
}

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

  ll a, b, n, mv = 0, v;
  cin >> a >> b >> n;

  if (b <= n)
    cout << f(a, b, b - 1) << endl;
  else
    cout << f(a, b, n) << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
using ll = long long int;
using ull = unsigned long long int;
#define vll vector<ll>

#define FOR(i, b, e) for (int i = (b); i < (e); ++i)
#define REP(i, e) FOR(i, 0, e)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define REV(v) reverse((v).begin(), (v).end())
#define IN(v) cin >> (v);
#define VIN(v, n) REP(i, n) cin >> v[i];
#define OUT(v) cout << (v) << endl;
#define YN(b) OUT((b) ? "YES" : "NO")
#define Yn(b) OUT((b) ? "Yes" : "No")
#define yn(b) OUT((b) ? "yes" : "no")

const ll MOD = 1000000007;

ll f(ll a, ll b, ll x) {
  return floor(a * x / (double)b) - a * floor(x / (double)b);
}

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

  ll a, b, n, mv = 0, v;
  cin >> a >> b >> n;

  REP(i, min(b, n) + 1) {
    v = f(a, b, i);
    mv = max(v, mv);
    if (mv != 0 && v == 0)
      break;
  }

  cout << mv << endl;

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

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

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


Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  long long int a, b, n, max = 0, atai;
  cin >> a >> b >> n;
  for (int i = 1; i <= n; i++) {
    atai = (a * i / b) - a * (i / b);
    if (max < atai)
      max = atai;
  }
  cout << max << 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;
  cin >> a >> b >> n;
  long long int ans = INT_MIN;
  if (n < b) {
    ans = (a * n) / b;
  } else {
    long long int x = b - 1;
    ans = (a * x) / b;
  }
  cout << ans;
  return 0;
}

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 ans = INT_MIN;
  if (n < b) {
    ans = (a * n) / b;
  } else {
    long long int x = b - 1;
    long long int t;
    while (x <= n) {
      t = (a * x) / b - a * (x / b);
      ans = max(ans, t);
      x = x + b;
    }
  }
  cout << ans;
  return 0;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <tuple>
#include <unordered_map>
#include <vector>
using namespace std;
typedef long long ll;

int main(int argc, char *argv[]) {
  ll i;
  ll a, b, n;
  ll ans = 0;
  ll tmp, start;
  cin >> a >> b >> n;
  start = min(n, b - 1);
  // for (i = start; i <= n; i += b) {
  // 	tmp = (a * i) / b - a * (i / b);
  // 	if (tmp > ans)
  // 		ans = tmp;
  // }
  if (n <= b - 1) {
    start = n;
    ans = (a * start) / b;
  } else {
    ll altans;
    start = n - (n % b + 1);
    altans = (a * n) / b - a * (n / b);
    ans = (a * start) / b - a * (start / b);
    ans = max(ans, altans);
  }

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


Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <tuple>
#include <unordered_map>
#include <vector>
using namespace std;
typedef long long ll;

int main(int argc, char *argv[]) {
  ll i;
  ll a, b, n;
  ll ans = 0;
  ll tmp, start;
  cin >> a >> b >> n;
  start = min(n, b - 1);
  for (i = start; i <= n; i += b) {
    tmp = (a * i) / b - a * (i / b);
    if (tmp > ans)
      ans = tmp;
  }

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

#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <deque>     // deque
#include <iomanip>   // setprecision
#include <iostream>  // cout, endl, cin
#include <map>       // map
#include <math.h>    // sqrt
#include <queue>     // queue, priority_queue
#include <set>       // set
#include <stack>     // stack
#include <string>    // string, to_string, stoi
#include <tuple>     // tuple, make_tuple
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <utility>       // pair, make_pair
#include <vector>        // vector
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vb = vector<bool>;
using vll = vector<long long>;
using pii = pair<int, int>;
using psi = pair<string, int>;

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


Error: TLE

Fixed submission:

#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <deque>     // deque
#include <iomanip>   // setprecision
#include <iostream>  // cout, endl, cin
#include <map>       // map
#include <math.h>    // sqrt
#include <queue>     // queue, priority_queue
#include <set>       // set
#include <stack>     // stack
#include <string>    // string, to_string, stoi
#include <tuple>     // tuple, make_tuple
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <utility>       // pair, make_pair
#include <vector>        // vector
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vb = vector<bool>;
using vll = vector<long long>;
using pii = pair<int, int>;
using psi = pair<string, int>;

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

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

ll A, B, N;

ll f(ll i) { return (A * i) / B - A * (i / B); }

int main() {
  cin >> A >> B >> N;
  cout << f(min(N, B - 1)) << endl;
}


Error: TLE

Fixed submission:

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

ll A, B, N;

int main() {
  cin >> A >> B >> N;
  ll ans = 0;
  for (ll i = 0; i < min(B, N + 1); 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>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  ll a, b, n, ans, floor, dummy = 0;
  cin >> a >> b >> n;
  if (b > n) {
    floor = a * n / b;
  } else {
    ll c = b * (n / b);
    for (ll i = b - 1; i <= n; i += b) {
      floor = a * i / b - a * (i / b);
      if (floor > dummy) {
        dummy = floor;
      } else {
        break;
      }
    }
    for (ll i = n; i >= c; i--) {
      floor = a * i / b - a * (i / b);
      if (floor > dummy) {
        dummy = floor;
      } else {
        break;
      }
    }
    floor = dummy;
  }
  cout << floor << endl;
  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  ll a, b, n, ans, floor, dummy = 0;
  cin >> a >> b >> n;
  if (b > n) {
    floor = a * n / b;
  } else {
    ll c = b * (n / b);
    for (ll i = b - 1; i <= n; i += b) {
      floor = a * i / b - a * (i / b);
      if (floor > dummy) {
        dummy = floor;
      } else {
        break;
      }
    }
    for (ll i = c; i <= n; i++) {
      floor = a * i / b - a * (i / b);
      if (floor >= dummy) {
        dummy = floor;
      }
    }
    floor = dummy;
  }
  cout << floor << endl;
  return 0;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vll;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define Sort(a) sort(a.begin(), a.end())
#define fin(ans) cout << (ans) << endl
const int INF = 1 << 30;
const ll MOD = 1000000007;

int main() {
  ll A, B, N;
  ll max = 0;
  cin >> A >> B >> N;
  // A = 1<<6, B = 1<<12 , N<<12;
  if (B > N) {
    long double a = (A * N) / B;
    ll tmp = ll(a);
    cout << tmp << endl;
    return 0;
  } else {
    N = B - 1;
    long double a = (A * N) / B, b = N / B;
    ll tmp = ll(a) - A * ll(b);
    cout << tmp << endl;
    return 0;
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vll;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define Sort(a) sort(a.begin(), a.end())
#define fin(ans) cout << (ans) << endl
const int INF = 1 << 30;
const ll MOD = 1000000007;

int main() {
  ll A, B, N;
  ll max = 0;
  cin >> A >> B >> N;
  // A = 1<<6, B = 1<<12 , N<<12;
  if (B > N) {
    long double a = (A * N) / B;
    ll tmp = ll(a);
    cout << tmp << endl;
    return 0;
  }
  for (ll i = 1; i <= N; i++) {
    long double a = (A * i) / B, b = i / B;
    ll tmp = ll(a) - A * ll(b);
    max = std::max(max, tmp);
  }

  cout << max << endl;
}