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

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>

#define int long long
#define R register
#define IL inline
#define Rf(a, b, c) for (R int(a) = (b); (a) <= (c); ++(a))
#define Tf(a, b, c) for (R int(a) = (b); (a) >= (c); --(a))
#define MP make_pair
#define PA pair<int, int>
#define MES(a, b) memset((a), (b), sizeof((a)))
#define MEC(a, b) memcpy((a), (b), sizeof((b)))
#define D double

using namespace std;

int A, B, n, ans, sum;

IL int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch > '9' || ch < '0') {
    if (ch == '-')
      f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x *= 10;
    x += (ch - '0');
    ch = getchar();
  }
  return x * f;
}
IL void write(int x) {
  if (x < 0)
    putchar('-'), x = -x;
  if (x > 9)
    write(x / 10);
  putchar(x % 10 + '0');
}

signed main() {
  A = read();
  B = read();
  n = read();
  /*Tf(x,n,1)
          if(floor(A*x/B)-A*floor(x/B)>ans) {
                  ans=floor(A*x/B)-A*floor(x/B);
                  cout<<x<<endl;
          }*/

  sum = sum = floor(A * n / B) - A * floor(n / B);
  int x = n / B * B - 1; // cout<<x<<endl;
  if (x > 0)
    if (floor(A * x / B) - A * floor(x / B) > sum)
      sum = floor(A * x / B) - A * floor(x / B);
  //	write(ans);puts("");
  write(sum);

  return 0;
}
// 984521 526541 523232

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>

#define int long long
#define R register
#define IL inline
#define Rf(a, b, c) for (R int(a) = (b); (a) <= (c); ++(a))
#define Tf(a, b, c) for (R int(a) = (b); (a) >= (c); --(a))
#define MP make_pair
#define PA pair<int, int>
#define MES(a, b) memset((a), (b), sizeof((a)))
#define MEC(a, b) memcpy((a), (b), sizeof((b)))
#define D double

using namespace std;

int A, B, n, ans, sum;

IL int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch > '9' || ch < '0') {
    if (ch == '-')
      f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x *= 10;
    x += (ch - '0');
    ch = getchar();
  }
  return x * f;
}
IL void write(int x) {
  if (x < 0)
    putchar('-'), x = -x;
  if (x > 9)
    write(x / 10);
  putchar(x % 10 + '0');
}

signed main() {
  A = read();
  B = read();
  n = read();
  /*Tf(x,n,1)
          if(floor(A*x/B)-A*floor(x/B)>ans)
                  ans=floor(A*x/B)-A*floor(x/B);*/
  sum = sum = floor(A * n / B) - A * floor(n / B);
  for (int x = B - 1; x <= n; x += B)
    if (floor(A * x / B) - A * floor(x / B) > sum)
      sum = floor(A * x / B) - A * floor(x / B);
  //	write(ans);puts("");
  write(sum);

  return 0;
}
// 984521 526541 523232
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;

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

  ll increment;
  if (N > B) {
    increment = N;
  } else {
    increment = B;
  }

  ll val_max = 0;
  for (ll i = min(N, (B - 1)); i <= N; i += increment) {
    ll tmp = (A * i) / B - A * (i / B);
    val_max = max(val_max, tmp);
  }

  cout << val_max << 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;

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

  ll val_max = 0;
  for (ll i = 1; i <= N; i++) {
    ll tmp = (A * i) / B - A * (i / B);
    val_max = max(val_max, tmp);
  }

  cout << val_max << endl;

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

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

#define ll long long
#define rep(i, N) for (ll i = 0; i < N; i++)
const int mx = 2e5;

int main(void) {

  ll A, B, N;
  cin >> A >> B >> N;

  ll max = 0;

  if ((B - 1) < N) {
    cout << ((A * (B - 1)) / B) - A * ((B - 1) / B);
  } else {
    cout << ((A * N) / B) - A * (N / B);
  }
  return 0;
}


Error: TLE

Fixed submission:

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

#define ll long long
#define rep(i, N) for (ll i = 0; i < N; i++)
const int mx = 2e5;

int main(void) {

  ll A, B, N;
  cin >> A >> B >> N;

  ll max = 0;

  for (ll i = 0; i <= (B - 1) && i <= N; i++) {
    ll ans = (A * i) / B - A * (i / B);
    if (ans > max)
      max = ans;
  }

  cout << max;

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

#include <iostream>
using namespace std;

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

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

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  long long int a, b, n, x, x_max, v, v_max;
  cin >> a >> b >> n;
  v_max = (a * n / b) - a * (n / b);

  for (x = n; x >= n / b; x--) {
    v = (a * x / b) - a * (x / b);
    if (v_max < v) {
      v_max = v;
    }
  }
  cout << v_max << endl;

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

#include <iostream>

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

  int64_t starter = N / B;
  starter *= B;
  if (starter == 0)
    starter = B;
  int64_t max_num = 0;
  for (int64_t x = starter; x <= N; x += B) {
    int64_t calcx = x - 1;
    int64_t first = A * calcx / B;
    int64_t second = calcx / B;

    int64_t result = first - A * second;
    if (max_num < result)
      max_num = result;
  }
  int64_t calcx = N;
  int64_t first = A * calcx / B;
  int64_t second = calcx / B;

  int64_t result = first - A * second;
  if (max_num < result)
    max_num = result;

  std::cout << max_num;
}

Error: TLE

Fixed submission:

#include <iostream>

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

  int64_t starter = N / B;
  starter *= B;
  if (starter == 0)
    starter = B;
  int64_t max_num = 0;
  for (int64_t x = B; x <= N; x += B) {
    int64_t calcx = x - 1;
    int64_t first = A * calcx / B;
    int64_t second = calcx / B;

    int64_t result = first - A * second;
    if (max_num < result)
      max_num = result;
  }
  int64_t calcx = N;
  int64_t first = A * calcx / B;
  int64_t second = calcx / B;

  int64_t result = first - A * second;
  if (max_num < result)
    max_num = result;

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

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <fstream>
#include <iostream>
#include <set>
#include <sstream>
#include <typeinfo>
#include <vector>

using namespace std;

int main(void) {
  float a, b, n, mx, i, temp;
  cin >> a >> b >> n;
  mx = floor(a * 1 / b) - a * floor(1 / b);
  for (i = 1; i <= b; i += floor(b / a)) {
    if (i > n)
      break;
    temp = floor(a * i / b) - a * floor(i / b);
    if (mx <= temp) {
      mx = temp;
    } else {
      break;
    }
    if (b / a < 1) {
      i++;
    }
  }
  cout << (long long)mx << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <fstream>
#include <iostream>
#include <set>
#include <sstream>
#include <typeinfo>
#include <vector>

using namespace std;

int main(void) {
  float a, b, n, mx = -1000000, i, temp;
  cin >> a >> b >> n;
  for (i = n; i > 0; i--) {
    temp = floor(a * i / b) - a * floor(i / b);
    if (mx <= temp) {
      mx = temp;
    } else {
      break;
    }
  }
  cout << (long long)mx << endl;
  return 0;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <stdio.h>
using namespace std;
int main(void) {
  long long a, b, n, i, minn;
  scanf("%lld %lld %lld", &a, &b, &n);
  minn = min(b - 1, n);

  printf("%lld", (a * minn) / b - a * (minn / b));
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <stdio.h>
using namespace std;
int main(void) {
  long long a, b, n, i, minn, maxx = -1;
  scanf("%lld %lld %lld", &a, &b, &n);
  minn = min(b, n);
  for (i = 1; i <= minn; i++)
    maxx = max(maxx, (a * i) / b - a * (i / b));
  printf("%lld", maxx);
  return 0;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <bitset>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (ll i = 0; i < n; i++)
const long long mod = 1000000007;
typedef long long int ll;
typedef pair<ll, ll> P;
const vector<int> di = {-1, 0, 1, 0};
const vector<int> dj = {0, 1, 0, -1};
const double PI = 3.14159265358979323846;

int main() {

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

  ll ans = 0;

  if (n < b) {
    ans = (a * n) / b - a * (n / b);
    cout << ans << endl;
  } else {
    ll cnt = n / b;
    ll num = 0;
    for (ll i = (cnt - 1); i < cnt; i++) {
      num = b * (i + 1) - 1;
      ans = max(ans, (a * num) / b - a * (num / b));
    }
    cout << ans << endl;
  }

  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (ll i = 0; i < n; i++)
const long long mod = 1000000007;
typedef long long int ll;
typedef pair<ll, ll> P;
const vector<int> di = {-1, 0, 1, 0};
const vector<int> dj = {0, 1, 0, -1};
const double PI = 3.14159265358979323846;

int main() {

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

  ll ans = 0;

  if (n < b) {
    ans = (a * n) / b - a * (n / b);
    cout << ans << endl;
  } else {
    ll cnt = n / b;
    ll num = 0;
    for (ll i = (cnt / 2); i < cnt; i++) {
      num = b * (i + 1) - 1;
      ans = max(ans, (a * num) / b - a * (num / b));
    }
    cout << ans << endl;
  }

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

#include <bits/stdc++.h>
using namespace std;
int main() {
  int A;
  int64_t B, N;
  cin >> A >> B >> N;
  int ans = 0;
  if (B > N) {
    cout << int(A * N / B) << endl;
  } else if (B == N) {
    cout << max(int(A * (N - 1) / B), int(A * N / B) - A * int(N / B)) << endl;
  } else {
    cout << max(int(A * (int(N / B) * B - 1) / B) -
                    A * int((int(N / B) * B - 1) / B),
                int(A * N / B) - A * int(N / B))
         << endl;
  }
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int A;
  int64_t B, N;
  cin >> A >> B >> N;
  int ans = 0;
  for (int i = 1; i < N + 1; i++) {
    ans = max(ans, int(A * i / B) - A * int(i / B));
  }
  cout << ans << endl;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define int long long
int a, b, n, ans;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
void tri(int x) { ans = max(ans, (a * x) / b - a * (x / b)); }
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> a >> b >> n;
  clock_t start = clock();
  for (int x = min(b - 1, n); x <= n; x += b) {
    tri(x);
    if ((double)(clock() - start) / CLOCKS_PER_SEC > 0.95)
      break;
  }
  cout << ans;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define int long long
int a, b, n, ans;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> a >> b >> n;
  for (int x = min(b - 1, n); x <= n; x += b) {
    ans = max(ans, (a * x) / b - a * (x / b));
  }
  cout << ans;
}
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 < (int)(n); i++)

int main() {
  ll a, b, n;
  cin >> a >> b >> n;
  ll ans;
  if (b > n) {
    ans = (a * n) / b - a * (n / b);
  } else {
    ans = (a * (b - 1)) / b - a * ((b - 1) / 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 < (int)(n); i++)

int main() {
  ll a, b, n;
  cin >> a >> b >> n;
  ll ans = -10000100;
  for (ll x = 0; x <= n; x++) {
    ll f = (a * x) / b - a * (x / b);
    ans = max(ans, f);
  }
  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, c, x;
  cin >> a >> b >> c;
  if (b - 1 < c) {
    x = b - 1;
  } else {
    x = c;
  }
  cout << x * a / b << endl;
}

Error: TLE

Fixed submission:

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

int main() {
  long long int a, b, c;
  cin >> a >> b >> c;
  long long int maxc = 0;
  long long int minc = 0;
  for (int x = 0; x <= c; x++) {
    if (maxc <= ((int)(a * x / b) - a * (int)(x / b))) {
      maxc = (int)(a * x / b) - a * (int)(x / b);
    }
  }
  cout << maxc << endl;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <set>
#include <string>
#include <vector>

using namespace std;

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

  cin >> A >> B >> N;

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

  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <set>
#include <string>
#include <vector>

using namespace std;

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

  cin >> A >> B >> N;

  long long ans = 0;
  long long right = N / 2;
  int i = 0;

  long long f1 = A * right / B;
  long long s1 = A * (right / B);
  long long f2 = A * right / B;
  long long s2 = A * (right / B);

  if (f2 - s2 > f1 - s1) {
    i = right;
  }

  for (; i <= N; i++) {
    long long f = A * i / B;
    long long s = A * (i / B);

    if (ans > f - s) {
      break;
    }
    ans = f - s;
  }

  cout << ans << endl;

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

#include <bits/stdc++.h>

using namespace std;

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

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

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

  for (long i = 0; i <= n; i++) {
    long tmp = (a * i) / b - a * (i / b);
    ans = max(ans, tmp);
  }
  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 i = min(B - 1, N);

  cout << (i * A) / B - A * (i / B) << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

int main() {
  long long int A, B, N;
  int ans = 0;
  cin >> A >> B >> N;
  int c = 0;
  long long int i = 0;
  while (true) {
    c++;
    i = min((B - 1) * c, N);
    int f = (i * A) / B - A * (i / B);
    ans = max(ans, f);
    if (i >= N)
      break;
  }

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

#include <bits/stdc++.h>
#define all(x) (x).begin, (x).end()
using namespace std;
typedef long long int64;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1 << 29;
const long long INFL = 1e18;
const int MOD = 1000000007;
const int MAX = 210000;
const int MAX_NUM = 999999999;
void solve() {
  double A, B, N;
  cin >> A >> B >> N;
  int64 x = (N < (B - 1) ? N : B - 1);
  int64 ans = 0;
  int p = floor((A * x) / B);
  int q = A * floor(x / B);
  int64 tmp = p - q;
  ans = max(ans, tmp);
  cout << ans << endl;
  return;
}
int main() {
  solve();
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define all(x) (x).begin, (x).end()
using namespace std;
typedef long long int64;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1 << 29;
const long long INFL = 1e18;
const int MOD = 1000000007;
const int MAX = 210000;
const int MAX_NUM = 999999999;
void solve() {
  double A, B, N;
  cin >> A >> B >> N;
  int64 ans = 0;
  for (int x = 0; x <= N; ++x) {
    int p = floor((A * x) / B);
    int q = A * floor(x / B);
    if (q != 0)
      break;
    int64 tmp = p - q;
    ans = max(ans, tmp);
  }
  cout << ans << endl;
  return;
}
int main() {
  solve();
  return 0;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
#include <algorithm>
#include <cmath>
int main() {
  long int a, b, n, high = 0, i;
  scanf("%ld %ld %ld", &a, &b, &n);
  i = min(b - 1, n);

  high = floor(a * i / b) - a * floor(i / b);

  printf("%ld", high);
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
#include <algorithm>
#include <cmath>
int main() {
  long int a, b, n, high = 0, i, temp;
  scanf("%ld %ld %ld", &a, &b, &n);

  for (i = 1; i <= min(n, b - 1); i++) {
    temp = floor(a * i / b) - a * floor(i / b);
    high = max(high, temp);
  }
  printf("%ld", high);
  return 0;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <queue>
#include <sstream>
#include <string>
#include <vector>

using namespace std;

#define ll long long
#define vecll vector<long long>
#define vec2ll vector<vector<long long>>
#define vecbool vector<bool>
#define vecpairll vector<pair<long long, long long>>
#define forll(s, a, b) for (long long s = a; s < b; s++)
#define forllde(s, a) for (long long s = a; s >= 0; s--)

int main() {
  ll a, b, n, ans = 0;
  string s = "NG";

  cin >> a >> b >> n;

  ll i = min(n, b - 1);
  if (b == 1) {
    ans = 0;
  } else {
    while (i <= n) {
      double buf1 = floor((double)(a * i) / (double)b);
      double buf2 = (double)a * floor((double)i / (double)b);

      double buf = buf1 - buf2;

      ans = max(ans, (ll)buf);

      if (i / b == n)
        i++;
      else
        i += b;
    }
  }

  cout << ans;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <queue>
#include <sstream>
#include <string>
#include <vector>

using namespace std;

#define ll long long
#define vecll vector<long long>
#define vec2ll vector<vector<long long>>
#define vecbool vector<bool>
#define vecpairll vector<pair<long long, long long>>
#define forll(s, a, b) for (long long s = a; s < b; s++)
#define forllde(s, a) for (long long s = a; s >= 0; s--)

int main() {
  ll a, b, n, ans = 0;
  string s = "NG";

  cin >> a >> b >> n;

  ll i = min(n, b - 1);

  while (i <= n) {
    double buf1 = floor((double)(a * i) / (double)b);
    double buf2 = (double)a * floor((double)i / (double)b);

    double buf = buf1 - buf2;

    ans = max(ans, (ll)buf);

    if (i / b == n)
      i++;
    else
      i += b;
  }

  cout << ans;
}
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;
  ll i = min(b - 1, n);
  ll ans = ll(floor(a * i / b) - a * floor(i / 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)
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;
  for (int i = 1; i <= n; ++i) {
    ans = max(ans, ll(floor(a * i / b) - a * floor(i / b)));
  }
  cout << ans << endl;
  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 REP(i, a, b) for (int i = (int)(a); i < (int)(b); i++)

using ll = long long;

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

  int maxv = 0;
  if (n < b) {
    // n<=bってことは[x/b]=0こていなのでAxがクソでかいほうがいいのでは？
    /*long long int A,B;
    for(int i=1;i<=n;i++){
      A = int(a*i/b);
      B = int(i/b);
      maxv = max(maxv, int(A-B*a) );
    }*/
    double A;
    A = double(a * n / b);
    maxv = floor(A);
    cout << maxv << endl;
  } else {
    double A, B;
    long long int i = b - 1;
    A = double(a * i / b);
    B = double(i / b);
    maxv = max(maxv, int(floor(A) - floor(B) * a));

    cout << maxv << endl;
  }
}

/*
floor は x=nb+m とおくとnによらずmのみで決定する
またmが大きい時差が最大になる
*/

Error: TLE

Fixed submission:

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

using ll = long long;

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

  int maxv = 0;
  if (n <= b) {
    long long int A, B;
    for (int i = 1; i <= n; i++) {
      A = int(a * i / b);
      B = int(i / b);
      maxv = max(maxv, int(A - B * a));
    }
    cout << maxv << endl;
  } else {
    double A, B;
    long long int i = b - 1;
    A = double(a * i / b);
    B = double(i / b);
    maxv = max(maxv, int(floor(A) - floor(B) * a));

    cout << maxv << endl;
  }
}

/*
floor は x=nb+m とおくとnによらずmのみで決定する
またmが大きい時差が最大になる
*/
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cmath>
#include <iostream>
using namespace std;
int main() {
  long long a, b, n, x, t, res = 0;
  cin >> a >> b >> n;
  x = min(b - 1, n);
  res = (long long)floor(a * x / b);
  cout << res << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
using namespace std;
int main() {
  long long a, b, n, x, t, res = 0;
  cin >> a >> b >> n;
  x = min(b - 1, n);
  if (a == 1) {
    res = 0;
  } else if (a >= b) {
    res = (a * x - ((a * x) % b)) / b;
  } else {
    for (; x >= 0; x--) {
      if (a * x < res)
        break;
      t = (a * x - ((a * x) % b)) / b;
      res = max(res, t);
    }
  }
  cout << res << endl;
  return 0;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cassert>
#include <cmath>
#include <iostream>
#include <numeric>
#include <vector>
using namespace std;
using ll = long long;

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

  ll a, b, n;
  cin >> a >> b >> n;
  ll res = ((a * n) / b) - a * (n / b);
  if (b > 1e6) {
    for (ll k = 0; k * b - 1 <= n; ++k) {
      ll x = k * b - 1;
      res = max(res, ((a * x) / b) - a * (x / b));
    }
  } else {
    for (ll x = 0; x <= min(n, 3 * b); ++x) {
      res = max(res, ((a * x) / b) - a * (x / b));
    }
  }
  cout << res << "\\n";

  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cassert>
#include <cmath>
#include <iostream>
#include <numeric>
#include <vector>
using namespace std;
using ll = long long;

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

  ll a, b, n;
  cin >> a >> b >> n;
  ll res = ((a * n) / b) - a * (n / b);
  if (b > 1e6) {
    for (ll k = 0; k * b - 1 <= n; ++k) {
      ll x = k * b - 1;
      res = max(res, ((a * x) / b) - a * (x / b));
    }
  } else {
    for (ll x = 0; x <= n; ++x) {
      res = max(res, ((a * x) / b) - a * (x / b));
    }
  }
  cout << res << "\\n";

  return 0;
}