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

/* ****TCIITB**** */

#include <bits/stdc++.h>
#define io                                                                     \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define ll long long
#define pb push_back
#define endl '\\n'
#define pii pair<ll int, ll int>
#define vi vector<ll int>
#define all(a) (a).begin(), (a).end()
#define F first
#define S second
#define sz(x) (ll int)x.size()
#define hell 1000000007
#define rep(i, a, b) for (ll int i = a; i < b; i++)
#define lbnd lower_bound
#define ubnd upper_bound
#define bs binary_search
#define mp make_pair
#define time                                                                   \\
  cerr << "\\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\\n";
using namespace std;

#define N 100005

int main() {

  io

      ll a,
      b, n;
  cin >> a >> b >> n;
  ll zz = min(50000000LL, n);
  ll res = 0;
  rep(i, 0, zz + 1) {
    ll v1 = i * a;
    ll res1 = (v1 / b);
    ll res2 = (i / b);
    res1 = (res1 - res2 * a);
    res = max(res, res1);
  }
  ll z1 = max(1LL, n - 50000000);
  rep(i, z1, n + 1) {
    ll v1 = i * a;
    ll res1 = (v1 / b);
    ll res2 = (i / b);
    res1 = (res1 - res2 * a);
    res = max(res, res1);
  }
  if (b - 1 <= n) {
    ll v1 = (b - 1) * a;
    ll res1 = (v1 / b);
    ll res2 = ((b - 1) / b);
    res1 = (res1 - res2 * a);
    res = max(res, res1);
  }
  cout << res;
}

Error: TLE

Fixed submission:

/* ****TCIITB**** */

#include <bits/stdc++.h>
#define io                                                                     \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define ll long long
#define pb push_back
#define endl '\\n'
#define pii pair<ll int, ll int>
#define vi vector<ll int>
#define all(a) (a).begin(), (a).end()
#define F first
#define S second
#define sz(x) (ll int)x.size()
#define hell 1000000007
#define rep(i, a, b) for (ll int i = a; i < b; i++)
#define lbnd lower_bound
#define ubnd upper_bound
#define bs binary_search
#define mp make_pair
#define time                                                                   \\
  cerr << "\\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\\n";
using namespace std;

#define N 100005

int main() {

  io

      ll a,
      b, n;
  cin >> a >> b >> n;
  ll zz = min(50000000LL, n);
  ll res = 0;
  rep(i, 0, zz + 1) {
    ll v1 = i * a;
    ll res1 = (v1 / b);
    ll res2 = (i / b);
    res1 = (res1 - res2 * a);
    res = max(res, res1);
  }
  ll z1 = max(1LL, n - 50000000);
  rep(i, 0, n + 1) {
    ll v1 = i * a;
    ll res1 = (v1 / b);
    ll res2 = (i / b);
    res1 = (res1 - res2 * a);
    res = max(res, res1);
  }
  cout << res;
}
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 ll;
using namespace std;

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

  ll x = n < b ? n : b - 1;
  ll ans = floor((a * x) / b) - a * floor(x / 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++)
typedef long long ll;
using namespace std;

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;

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


Error: TLE

Fixed submission:

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

int64_t A, B, N;

int64_t f(double t) { return (int64_t)t; }

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

#include <bits/stdc++.h>
#define ll long long
#define pi 3.14159265358979
#define mod 1000000007
#define rep(i, n) for (ll i = 0; i < n; i++)
using namespace std;

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

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define ll long long
#define pi 3.14159265358979
#define mod 1000000007
#define rep(i, n) for (ll i = 0; i < n; i++)
using namespace std;

int main() {
  ll n, a, b, k, max = 0;
  cin >> a >> b >> n;
  rep(i, n + 1) {
    k = (a * i / b) - a * (i / b);
    if (k > max) {
      max = k;
    }
  }
  cout << max;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

// you**can**do**anything :~
#include <bits/stdc++.h>
#define ll long long
#define read(i) scanf("%lli", &i)
const int maxn = 5e5 + 10;
using namespace std;
// vector< pair< ll , ll > >abj[545445];
int main() {
  ll a, b, n, ma = -76376735675;

  read(a);
  read(b);
  read(n);

  ll g = min(b, n);

  ll h = floor((a * g) / b) - a * floor(g / b);
  ll h2 = floor((a * (g - 1)) / b) - a * floor((g - 1) / b);
  h = max(h, h2);

  printf("%lli", h);
}


Error: TLE

Fixed submission:

// you**can**do**anything :~
#include <bits/stdc++.h>
#define ll long long
#define read(i) scanf("%lli", &i)
const int maxn = 5e5 + 10;
using namespace std;
// vector< pair< ll , ll > >abj[545445];
int main() {
  ll a, b, n, ma = -76376735675;

  read(a);
  read(b);
  read(n);

  for (int i = 1; i <= n; i++) {

    ll h = floor((a * i) / b) - a * floor(i / b);

    ma = max(ma, h);
  }
  printf("%lli", ma);
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define ll long long
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vii vector<pii>
#define vll vector<pll>
#define all(v) v.begin(), v.end()
#define mem(v, x) memset(v, x, sizeof(v))
#define N 100005

using namespace std;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  ll a, b, n;
  cin >> a >> b >> n;
  ll val = 0;
  if (n >= b - 1)
    val = a * (b - 1) / b;
  ll nval = a * n / b - (n / b) * a;
  val = max(val, nval);
  cout << val;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define ll long long
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vii vector<pii>
#define vll vector<pll>
#define all(v) v.begin(), v.end()
#define mem(v, x) memset(v, x, sizeof(v))
#define N 100005

using namespace std;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  ll a, b, n;
  cin >> a >> b >> n;
  ll val = 0;
  ll temp = b - 1;
  while (1) {
    if (temp > n)
      break;
    ll nval = a * temp / b - (temp / b) * a;
    if (nval < val)
      break;
    val = max(val, nval);
    temp += b;
  }
  ll nval = a * n / b - (n / b) * a;
  val = max(val, nval);
  cout << val;
}
Problem p02696 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn = 1e6 + 5;
ll res[maxn];
int main() {
  ios::sync_with_stdio(false);
  ll a, b, n;
  cin >> a >> b >> n;
  ll x = min(n, b - 1);
  cout << (a * x) / b - a * (x / b) << endl;
  /*for (ll i = 1 ; i <= n ; i++){
       ll l = a * i / b;
       ll r = a * (i / b);
       cout << i << " " << l - r << endl;
   }*/
  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn = 50 + 5;
int a[maxn], b[maxn], c[maxn], d[maxn];
int n, m, Q;
int ans = 0;
int res[maxn];
void dfs(int step, int last) {
  if (step == n + 1) {
    int cost = 0;
    for (int i = 1; i <= Q; i++) {
      if (res[b[i]] - res[a[i]] == c[i])
        cost += d[i];
    }
    ans = max(ans, cost);
    return;
  }
  for (int i = last; i <= m; i++) {
    res[step] = i;
    dfs(step + 1, i);
    res[step] = 0;
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> m >> Q;
  for (int i = 1; i <= Q; i++) {
    cin >> a[i] >> b[i] >> c[i] >> d[i];
  }
  dfs(1, 1);
  cout << ans << endl;
  return 0;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <stdio.h>
#include <stdlib.h>

int floor(long long a, long long b, long long c) {
  long long max = 0;
  long long anser = 0;
  long long anser2 = 0;

  if (c >= b) {
    c = b - 1;
    anser = a * c / b;
    anser2 = c / b;
    max = anser - a * anser2;
  } else {
    anser = a * c / b;
    anser2 = c / b;
    max = anser - a * anser2;

    /*for (int i = 0; i <= c; i++) {
            anser = a * i / b;
            if (test != anser) {

                    long long anser2 = i / b;
                    long long anserA = anser - a * anser2;

                    if (anserA > max) {
                            max = anserA;
                    }
                    test = anser;
            }
    }*/
  }

  return max;
}

int main(int argc, char *argv[]) {
  long long a, b, c, d;

  std::cin >> a >> b >> c;

  d = floor(a, b, c);

  // printf("%d\\n", d);
  std::cout << d << std::endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
#include <stdio.h>
#include <stdlib.h>

int floor(long long a, long long b, long long c) {
  long long max = 0;
  long long anser = 0;
  long long anser2 = 0;
  if (c > b) {
    c = b - 1;
    anser = a * c / b;
    anser2 = c / b;
    max = anser - a * anser2;
  } else {

    long long test = -1;
    for (int i = 0; i <= c; i++) {
      anser = a * i / b;
      if (test != anser) {

        long long anser2 = i / b;
        long long anserA = anser - a * anser2;

        if (anserA > max) {
          max = anserA;
        }
        test = anser;
      }
    }
  }

  return max;
}

int main(int argc, char *argv[]) {
  long long a, b, c, d;

  std::cin >> a >> b >> c;

  d = floor(a, b, c);

  // printf("%d\\n", d);
  std::cout << d << std::endl;
  return 0;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cmath>
#include <iostream>
using namespace std;
#define ll long long
int main() {
  double a, b, lim, max = floor(a * lim / b) - a * floor(lim / b);
  ;
  cin >> a >> b >> lim;
  for (ll i = (ll)lim; i >= (ll)lim; i--) {
    ll ans = floor(a * i / b) - a * floor(i / b);
    if (ans > max) {
      max = ans;
      break;
    }
  }
  if (lim < b)
    cout << floor(a * (lim) / b);
  else
    cout << floor(a * (b - 1) / b);
  // cout<<max;
  return 0;
}


Error: TLE

Fixed submission:

#include <cmath>
#include <iostream>
using namespace std;
#define ll long long
int main() {
  double a, b, lim, max = 0;
  cin >> a >> b >> lim;
  for (ll i = 0; i <= (ll)lim; i++) {
    ll ans = floor(a * i / b) - a * floor(i / b);
    if (ans > max)
      max = ans;
  }
  cout << max;
  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;
  // vector<vector<int>> input(q, vector<int>(4));

  int64_t loop = N / B + 1;
  int64_t x, ans, tmp;
  ans = 0;

  if (B == 1) {
    ans = 0;
  } else {
    for (int i = 1; i <= loop; i++) {
      if ((i * B - 1) < N)
        x = i * B - 1;
      else
        x = N;
      tmp = floor(A * x / B) - A * floor(x / B);
      if (tmp > ans)
        ans = tmp;
    }
  }

  cout << ans << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

int main() {
  int64_t A, B, N;
  cin >> A >> B >> N;
  // vector<vector<int>> input(q, vector<int>(4));

  int64_t loop = N / B + 1;
  int64_t x, ans, tmp;
  ans = 0;

  for (int i = 1; i <= loop; i++) {
    if ((i * B - 1) < N)
      x = i * B - 1;
    else
      x = N;
    tmp = floor(A * x / B) - A * floor(x / B);
    if (tmp > ans)
      ans = tmp;
  }

  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 ll = long long;
using namespace std;

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

  ll ans;
  ll max = 0;

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

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

  return 0;
}

Error: TLE

Fixed submission:

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

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

  ll ans;
  ll max = 0;

  for (ll i = 0; i <= n; i++) {
    ans = a * i / b - a * (i / b);
    if (ans > max)
      max = ans;
  }

  cout << max << endl;

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

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < 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 n = min(B, N);
  // ll ans = (A * n) / B;
  ll ans = 0;
  for (ll x = n - 2; x <= n; x++) {
    // ll x = i % B;
    ll y = (A * x) / B - A * (x / B);
    // ll y = (A * x) / B;
    ans = max(ans, y);
  }
  cout << ans << endl;
}


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 n = min(B, N);
  ll ans = 0;
  for (ll x = n / 2; x <= n; x++) {
    // ll x = i % B;
    ll y = (A * x) / B - A * (x / B);
    ans = max(ans, y);
  }
  cout << ans << endl;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cmath>
#include <iostream>

int main() {
  int A;
  long long B, N;
  long long ans;
  std::cin >> A >> B >> N;
  ans = (A * N) / B - (N / B) * A;
  // for(long long x=B-1;x<=N;x+=B){
  //     long long buf=(A*x)/B-(x/B)*A;
  //     if(ans<buf){
  //         ans=buf;
  //     }
  // }
  long long buf = ((N / B) - 1) * B + B - 1;
  buf = (A * buf) / B - (buf / B) * A;
  if (ans < buf) {
    ans = buf;
  }
  std::cout << ans;
}

Error: TLE

Fixed submission:

#include <cmath>
#include <iostream>

int main() {
  int A;
  long long B, N;
  long long ans;
  std::cin >> A >> B >> N;
  ans = (A * N) / B - (N / B) * A;
  for (long long x = B - 1; x <= N; x += B) {
    long long buf = (A * x) / B - (x / B) * A;
    if (ans < buf) {
      ans = buf;
    }
  }
  std::cout << ans;
}
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 s = min(b - 1, n);
  ll ans = floor(a * s / b) - a * floor(s / b);
  cout << ans << endl;
}


Error: TLE

Fixed submission:

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

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

#include <algorithm>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <stdlib.h>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int binary(int bina) {
  int ans = 0;
  for (int i = 0; bina > 0; i++) {
    ans = ans + (bina % 2) * pow(10, i);
    bina = bina / 2;
  }
  return ans;
}
long comb(int n, int r) {
  long ans = 1;
  for (int i = n; i > n - r; --i) {
    ans = ans * i;
  }
  for (int i = 1; i < r + 1; ++i) {
    ans = ans / i;
  }
  return ans;
}
using namespace std;
/*int main(){
    int n;std::cin >> n;
    int keta=0;
    while(true){
        keta++;
        if(n/10==0)break;
        n=n/10;
    }
    keta=keta-1;
    if(n>=7)n=3;
    else if(n>=5)n=2;
    else if(n>=3)n=1;
    int k=0;
    for(int i=3;i<=keta;i++){
        k+=comb(i-1,2);
        std::cout << k << std::endl;
    }std::cout << k << std::endl;
    k+=n*(keta);

    std::cout << k << std::endl;

}


*/

int main() {
  unsigned long long a, b, n;
  int s = 0;
  std::cin >> a >> b >> n;

  std::cout << a * min((b - 1), n) / b << std::endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <stdlib.h>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int binary(int bina) {
  int ans = 0;
  for (int i = 0; bina > 0; i++) {
    ans = ans + (bina % 2) * pow(10, i);
    bina = bina / 2;
  }
  return ans;
}
long comb(int n, int r) {
  long ans = 1;
  for (int i = n; i > n - r; --i) {
    ans = ans * i;
  }
  for (int i = 1; i < r + 1; ++i) {
    ans = ans / i;
  }
  return ans;
}
using namespace std;
/*int main(){
    int n;std::cin >> n;
    int keta=0;
    while(true){
        keta++;
        if(n/10==0)break;
        n=n/10;
    }
    keta=keta-1;
    if(n>=7)n=3;
    else if(n>=5)n=2;
    else if(n>=3)n=1;
    int k=0;
    for(int i=3;i<=keta;i++){
        k+=comb(i-1,2);
        std::cout << k << std::endl;
    }std::cout << k << std::endl;
    k+=n*(keta);

    std::cout << k << std::endl;

}


*/

int main() {
  unsigned long long a, b, n;
  int s = 0;
  std::cin >> a >> b >> n;
  int w;
  for (int i = 1; i < n + 1; i++) {
    w = (((a * i) / b) - a * (i / b));
    s = max(s, w);
  }
  std::cout << s << std::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 < (n); i++)
#define repd(i, a, b) for (int i = (a); i < (b); i++)
#define INF LLONG_MAX
#define mod 1000000007
typedef long long ll;
int main(void) {
  ll A, B, N, b;
  cin >> A >> B >> N;
  if (B > N)
    b = N;
  else
    b = B - 1;
  ll max_x = 0;
  for (ll i = 0; i < 100000; i++)
    max_x = max(max_x, A * (b - i) / B - A * ((b - i) / B));
  cout << max_x << 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 repd(i, a, b) for (int i = (a); i < (b); i++)
#define INF LLONG_MAX
#define mod 1000000007
typedef long long ll;
int main(void) {
  ll A, B, N, b;
  cin >> A >> B >> N;
  if (B > N)
    b = N;
  else
    b = B - 1;
  ll max_x = 0;
  for (ll i = 0; i < B; i++)
    max_x = max(max_x, A * (b - i) / B - A * ((b - i) / B));
  cout << max_x << endl;
  return 0;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

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

ll a, b, n;

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


Error: TLE

Fixed submission:

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

ll a, b, n;

int main(void) {
  scanf("%lld%lld%lld", &a, &b, &n);
  ll ans = a * (n) / b - a * ((n) / b);
  for (ll i = b - 1; i <= n; i += b) {
    ans = max(ans, a * i / b - a * (i / b));
  }
  printf("%lld\\n", ans);
  return 0;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

#define INF INT_MAX
#define UINF UINT_MAX
#define MOD 1000000007
#define REP(i, n) for (int i = 0; i < n; i++)
#define all(x) (x).begin(), (x).end()

typedef long long ll;
typedef std::pair<int, int> pii;

using namespace std;

ll temp(ll a, ll b, ll x) {
  ll axb = (long double)(a * x) / (long double)b;
  ll bx = (long double)x / (long double)b;
  // cout << axb << " " << a * bx << endl;
  return axb - a * bx;
}

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

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

  ll x = n > b - 1 ? b - 1 : n;
  ll ans = temp(a, b, x);

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


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

#define INF INT_MAX
#define UINF UINT_MAX
#define MOD 1000000007
#define REP(i, n) for (int i = 0; i < n; i++)
#define all(x) (x).begin(), (x).end()

typedef long long ll;
typedef std::pair<int, int> pii;

using namespace std;

ll temp(ll a, ll b, ll x) {
  ll axb = (long double)(a * x) / (long double)b;
  ll bx = (long double)x / (long double)b;
  // cout << axb << " " << a * bx << endl;
  return axb - a * bx;
}

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

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

  ll ans = 0;
  ll x = n;
  for (ll i = n; i >= 0; i--) {
    ans = max(temp(a, b, i), ans);
  }

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

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
ll a, b, n;
ll calc(ll x) { return floor((a * x) / b) - a * floor(x / b); }

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

Error: WA

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
ll a, b, n;
ll calc(ll x) {
  ll x1 = (a * x) / b;
  ll x2 = (x / b);
  x2 *= a;
  return x1 - x2;
}

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

#pragma GCC optimize("O2")
// #include <bits/stdc++.h>
#include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <numeric>
#include <vector>
using namespace std;
#define MOD 1000000007

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  long long a, b, n;
  cin >> a >> b >> n;
  // long long mx = -1  , c;
  long long m;
  if (n <= b - 1) {
    cout << floor(a * n / b) << "\\n";

  } else {
    m = b - 1;
    cout << floor(a * m / b) << "\\n";
  }
  // else {
  // 	for (int i = b - 1 ; i <= n ; i += b) {
  // 		c = floor(a * i / b) - a * floor(i / b);
  // 		mx = max(mx, c);
  // 	}
  // 	cout << mx << "\\n";
  // }

  return 0;
}


Error: TLE

Fixed submission:

#pragma GCC optimize("O2")
// #include <bits/stdc++.h>
#include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <numeric>
#include <vector>
using namespace std;
#define MOD 1000000007

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  long long a, b, n;
  cin >> a >> b >> n;
  long long mx = -1, c;
  if (n <= b - 1) {
    cout << floor(a * n / b) << "\\n";

  } else {
    for (int i = b - 1; i <= n; i += b) {
      c = floor(a * i / b) - a * floor(i / b);
      mx = max(mx, c);
    }
    cout << mx << "\\n";
  }

  return 0;
}