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

#include <algorithm>
#include <iostream>

using namespace std;

int main() {
  long long int a, b, n, ans = 0;

  cin >> a >> b >> n;

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

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>

using namespace std;

int main() {
  long long int a, b, n, ans = 0;

  cin >> a >> b >> n;

  for (long long int i = n - 170000000; i <= n; i++) {
    if ((((a * i) / b) - a * (i / b)) > ans) {
      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;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
typedef long long ll;

int main() {
  ll a, b, n, sum = 0;
  cin >> a >> b >> n;
  if (b > 1) {
    ll c = b - 1;
    while (c < n) {
      sum = max(sum, a * c / b - c / b * a);
      c += b;
    }
  }
  sum = max(sum, a * n / b - n / b * a);
  cout << sum;
}

Error: TLE

Fixed submission:

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

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

#include <bits/stdc++.h>
#define rep(i, n) for (long long int i = 0; i < n; i++)
#define _rep(i, m, n) for (long long int i = m; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int N = 1000000;
const ll mod = 1000000007;
using Graph = vector<vector<int>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll gcd(ll A, ll B) {
  if (B == 0)
    return A;
  return gcd(B, A % B);
}
ll lcm(ll A, ll B) { return A * B / gcd(A, B); }

/*------------------------------------------------------------------*/

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

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (long long int i = 0; i < n; i++)
#define _rep(i, m, n) for (long long int i = m; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int N = 1000000;
const ll mod = 1000000007;
using Graph = vector<vector<int>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll gcd(ll A, ll B) {
  if (B == 0)
    return A;
  return gcd(B, A % B);
}
ll lcm(ll A, ll B) { return A * B / gcd(A, B); }

/*------------------------------------------------------------------*/

int main() {
  ll a, b, n;
  cin >> a >> b >> n;
  ll x = n;
  while (true) {
    if (a * x % b == b - 1) {
      break;
    }
  }
  ll ans = (a * x / b) - a * (x / b);
  cout << ans << endl;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <string.h>
using namespace std;
typedef long long ll;
int main() {
  ll a, b, n;
  cin >> a >> b >> n;
  ll m = 0;
  m = a * min(b - 1, n) / b;
  cout << m << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#include <list>
using namespace std;
typedef long long ll;
int main() {
  double a, b, n, i, j;
  cin >> a >> b >> n;
  double max = 0, m1, mn;
  for (i = 1; i <= n; i++) {
    m1 = floor(a * i / b * 1.0) - a * floor(i / b * 1.0);
    if (max <= m1) {
      max = m1;
    }
  }
  cout << max;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define int long long int
using namespace std;
signed main() {
  int a, b, n;
  cin >> a >> b >> n;
  int x = min(b - 1, n);
  cout << floor((a * x) / b) - a * floor(x / b);
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define int long long int
using namespace std;
signed main() {
  int a, b, n;
  cin >> a >> b >> n;
  int maxi = INT_MIN;

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

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

int main() {
  ll a, b, n;
  cin >> a >> b >> n;
  ll ans = 0;
  ll tmp = 10000000;
  ll cnt = 0;
  if (n <= tmp) {
    for (ll i = 1; i <= n; i++) {
      ll axb = (a * i) / b;
      ll xb = i / b;
      xb = xb * a;
      /*if(ans<axb-xb){
          cout<<i<<" "<<axb<<" "<<xb<<endl;
      }*/
      ans = max(ans, axb - xb);
    }
  } else {
    for (ll i = n - tmp; i <= n; i++) {
      ll axb = (a * i) / b;
      ll xb = i / b;
      xb = xb * a;
      /*if(ans<axb-xb){
          cout<<i<<" "<<axb<<" "<<xb<<endl;
      }*/
      ans = max(ans, axb - xb);
    }
    for (ll i = 1; i <= tmp; i++) {
      ll axb = (a * i) / b;
      ll xb = i / b;
      xb = xb * a;
      /*if(ans<axb-xb){
          cout<<i<<" "<<axb<<" "<<xb<<endl;
      }*/
      ans = max(ans, axb - xb);
    }
    for (ll i = 10000001; i <= n - 10000000; i = i + 100000) {
      // cnt++;
      ll axb = (a * i) / b;
      ll xb = i / b;
      xb = xb * a;
      /*if(ans<axb-xb){
          cout<<i<<" "<<axb<<" "<<xb<<endl;
      }*/
      ans = max(ans, axb - xb);
      /*if(cnt>=10000000){
          i+=10000000000;
          cnt = 0;
      }*/
    }
  }
  cout << ans << endl;
}

Error: TLE

Fixed submission:

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

int main() {
  ll a, b, n;
  cin >> a >> b >> n;
  ll ans = 0;
  ll tmp = 10000000;
  ll cnt = 0;
  if (n <= tmp) {
    for (ll i = 1; i <= n; i++) {
      ll axb = (a * i) / b;
      ll xb = i / b;
      xb = xb * a;
      /*if(ans<axb-xb){
          cout<<i<<" "<<axb<<" "<<xb<<endl;
      }*/
      ans = max(ans, axb - xb);
    }
  } else {
    for (ll i = n - tmp; i <= n; i++) {
      ll axb = (a * i) / b;
      ll xb = i / b;
      xb = xb * a;
      /*if(ans<axb-xb){
          cout<<i<<" "<<axb<<" "<<xb<<endl;
      }*/
      ans = max(ans, axb - xb);
    }
    for (ll i = 1; i <= tmp; i++) {
      ll axb = (a * i) / b;
      ll xb = i / b;
      xb = xb * a;
      /*if(ans<axb-xb){
          cout<<i<<" "<<axb<<" "<<xb<<endl;
      }*/
      ans = max(ans, axb - xb);
    }
    for (ll i = 10000001; i <= n - 10000000; i++) {
      cnt++;
      ll axb = (a * i) / b;
      ll xb = i / b;
      xb = xb * a;
      /*if(ans<axb-xb){
          cout<<i<<" "<<axb<<" "<<xb<<endl;
      }*/
      ans = max(ans, axb - xb);
      if (cnt >= 10000000) {
        i += 10000000000;
        cnt = 0;
      }
    }
  }
  cout << ans << endl;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#include <boost/dynamic_bitset.hpp>
using namespace std;
using u64 = uint64_t;
using s64 = int64_t;

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

  u64 x = (N < B - 1) ? N : B - 1;
  u64 ans = (A * x / B) - A * (x / B);

  cout << ans;

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#include <boost/dynamic_bitset.hpp>
using namespace std;
using u64 = uint64_t;
using s64 = int64_t;

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

  u64 ans = 0;

  for (u64 x = 0; x <= N; x++) {
    u64 fAxB = (A * x) / B;
    u64 AfxB = A * (x / B);

    ans = max(ans, fAxB - AfxB);
  }

  cout << ans;

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

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

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

  cout << (a * min(n, (b - 1))) / b;

  return 0;
}


Error: TLE

Fixed submission:

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

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

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

  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, i, k;
  cin >> a >> b >> n;
  // k=((a*n)/b)-a*(n/b);
  // cout<<k<<endl;
  if (n >= b)
    k = ((a * (b - 1)) / b);
  else {
    k = (a * (n) / b);
  }

  cout << k << endl;
}


Error: TLE

Fixed submission:

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

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

int main() {
  int64_t a;
  cin >> a;
  int64_t b, n, R, L, RR, LL;
  cin >> b >> n;
  int64_t i = n / b - 1;

  while (b * i - 1 <= n) {
    i++;
  }
  int64_t x = b * (i - 1) - 1;
  R = (a * x) / b;
  L = x / b;
  RR = (a * n) / b;
  LL = n / b;
  cout << max(R - a * L, RR - a * LL) << endl;
}

Error: TLE

Fixed submission:

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

int main() {
  int a;
  cin >> a;
  int64_t b, n, R, L, RR, LL;
  cin >> b >> n;
  int64_t i = 0;

  while (b * i - 1 <= n) {
    i++;
  }
  int64_t x = b * (i - 1) - 1;
  R = (a * x) / b;
  L = x / b;
  RR = (a * n) / b;
  LL = n / b;
  cout << max(R - a * L, RR - a * LL) << endl;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
typedef long long ll;
int t;
string s;

int main() {
  ll a, b, n, x, mx = 0, d, lop;
  cin >> a >> b >> n;

  if (n >= b) {
    x = b - 1;
    lop = (n - b) / 2;
  } else
    x = n, lop = (b - n) / 2;

  while (x > lop) {
    d = ((a * x) / b) - (a * (x / b));
    if (d > mx) {
      mx = d;
      break;
    }

    x--;
  }
  cout << mx << endl;

  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
typedef long long ll;
int t;
string s;

int main() {
  ll a, b, n, x, mx = 0, d, lop;
  cin >> a >> b >> n;

  if (n > b) {
    x = b - 1;
    lop = (n - b) / 2;
  } else
    x = n, lop = (b - n) / 2;

  d = ((a * x) / b) - (a * (x / b));
  if (d > mx)
    mx = d;

  while (x > lop) {
    x--;
    d = ((a * x) / b) - (a * (x / b));
    if (d > mx) {
      mx = d;
      break;
    }
  }
  cout << mx << endl;

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

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

int main() {
  ll a, b, n;
  cin >> a >> b >> n;
  ll f = 0;
  // ll ans = 0;
  if (b == 1) {
    cout << 0 << endl;
    return 0;
  }
  if (b == 2) {
    cout << a / 2 << endl;
    return 0;
  }
  if (n < b) {
    cout << (a * n) / b - a * (n / b) << endl;
    return 0;
  } else {
    if (a % b == 0) {
      cout << a + (-a / b) << endl;
      return 0;
    } else {
      cout << a + (-a / b) - 1 << endl;
      return 0;
    }
  }
}

Error: TLE

Fixed submission:

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

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

#include <bits/stdc++.h>
using namespace std;
using i64 = int_fast64_t;
#define rep(i, N) for (i64 i = 0; i < N; i++)
#define Rep(i, k, N) for (i64 i = k; i < N; i++)
#define all(v) v.begin(), v.end()
#define eb emplace_back
#define Cout(s) cout << s << endl
string Yes(bool b) {
  if (b) {
    return "Yes";
  } else {
    return "No";
  }
}
string YES(bool b) {
  if (b) {
    return "YES";
  } else {
    return "NO";
  }
}

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

  auto f = [&](i64 x) -> i64 { return (A * x / B) - (A * (x / B)); };

  i64 m = 1, M = N;
  while (M - m > 2) {
    i64 c = (2 * m + M) / 3;
    i64 d = (m + 2 * M) / 3;

    if (f(c) < f(d))
      m = c;
    else
      M = d;

    // cout << m << " " << M << endl;
  }
  i64 res1 = 0, res2 = 0;
  // for(i64 n = 1; n <= sqrt(N); n++) res1 = max(res1, f(n));
  for (i64 n = N - sqrt(n); n <= N; n++)
    res2 = max(res2, f(n));

  if (N == 1)
    cout << f(1) << endl;
  else
    cout << max({f(m), f(m + 1), f(M), res2}) << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using i64 = int_fast64_t;
#define rep(i, N) for (i64 i = 0; i < N; i++)
#define Rep(i, k, N) for (i64 i = k; i < N; i++)
#define all(v) v.begin(), v.end()
#define eb emplace_back
#define Cout(s) cout << s << endl
string Yes(bool b) {
  if (b) {
    return "Yes";
  } else {
    return "No";
  }
}
string YES(bool b) {
  if (b) {
    return "YES";
  } else {
    return "NO";
  }
}

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

  auto f = [&](i64 x) -> i64 { return (A * x / B) - (A * (x / B)); };

  i64 ans = f(1);
  for (i64 x = N; x * x >= B; x--) {
    ans = max(ans, f(x));
  }

  if (N > 1e8) {
    for (i64 i = 1e8; i <= N; i++)
      ans = max(ans, f(i + 1ll));
  }

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

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

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

  int64_t x = 0;
  if (N < B - 1)
    x = N;
  else
    x = B - 1;
  printf("%ld\\n", (-A * (x % B) % B + A * (x % B)) / B);
  return 0;
}

Error: TLE

Fixed submission:

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

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

  int64_t max_xB = 0; // A(x%B)のmax
  for (int i = 0; i < N; i++) {
    int x = i + 1;
    max_xB = max(max_xB, x % B);
  }

  printf("%ld\\n", (-A * max_xB % B + A * max_xB) / B);
  return 0;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

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

using namespace std;

#define int long long

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

  if (b > n) {
    int faxb = floor(a * n / b);
    int afxb = a * floor(n / b);
    int ans = faxb - afxb;
    cout << ans << endl;
    return 0;
  }

  int faxb = floor(a * (b - 1) / b);
  int afxb = a * floor((b - 1) / b);
  int ans = faxb - afxb;
  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

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

using namespace std;

#define int long long

const int MIN = -1e18;

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

  int ans = MIN;
  for (int i = 0; i <= n; i++) {
    int faxb = floor(a * i / b);
    int afxb = a * floor(i / b);
    ans = max(ans, faxb - afxb);
  }

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

#include <bits/stdc++.h>

using namespace std;
#define ll long long int
int main() {
  ll a, b, c, y;
  cin >> a >> b >> c;

  if (c == b)
    y = floor((b - 1) * a / b);
  if (c < b)
    y = floor((c)*a / b);
  if (c > b) {
    y = floor((b - 1) * a / b);
  }

  cout << y;

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
#define ll long long int
int main() {
  ll a, b, n;
  cin >> a >> b >> n;
  long double i, ans = 0, max = 0;
  for (i = n; i >= sqrt(n); --i) {
    ans = floor((a * i) / b) - a * floor(i / b);
    if (max < ans)
      max = ans;
  }

  cout << max;

  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, C;

  cin >> A >> B >> N;
  C = min(B - 1, N);
  cout << ((A * C) / B) - A * (C / B) << endl;
}


Error: TLE

Fixed submission:

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

struct ST {
  int a;
  int b;
  int c;
  int d;
};

int main() {
  long long int A, B, N, C, D = 0;

  cin >> A >> B >> N;

  for (long long int x = 0; x <= N; x++) {
    C = floor((A * x) / B) - A * floor(x / B);
    if (C >= D) {
      D = C;
    } else
      break;
  }
  cout << D << endl;
}
Problem p02696 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iomanip>
#include <iostream>
#include <string>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)

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

Error: 0

Fixed submission:

#include <algorithm>
#include <iomanip>
#include <iostream>
#include <string>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)

int main() {
  int a, b, n;
  cin >> a >> b >> n;
  long long k[n];
  long long max = 0;
  rep2(i, 1, n + 1) {
    int s = (a * i) / b;
    int t = (i / b);
    k[i] = s - a * t;
    if (max < k[i]) {
      max = k[i];
    }
  }
  cout << max << 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 ans = 0;
  if (n < b) {
    ans = ((a * n) / b);
  }
  if (n == b) {
    ans = (a * (n - 1)) / b;
  }
  if (n > b) {
    for (long long int i = b - 1; i <= b + 1; i++) {
      if ((((a * i) / b) - a * (i / b)) > ans) {

        ans = ((a * i) / b) - a * (i / b);
      }
    }
  }
  if (ans > 0) {
    cout << ans;
  } else {
    cout << "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 = 0;
  if (n < b) {
    ans = ((a * n) / b);
  } else {
    ans = (a * (n - 1)) / b;
  }
  if (n > b) {
    for (long long int i = b - 1; i <= n; i++) {
      if ((((a * i) / b) - a * (i / b)) > ans) {

        ans = ((a * i) / b) - a * (i / b);
      }
    }
  }
  if (ans > 0) {
    cout << ans;
  } else {
    cout << "0";
  }
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;

int main() {
  long long x, a, b, n;
  cin >> a >> b >> n;
  if (n < b)
    x = n;
  else if (n >= b)
    x = b - 1;
  cout << floor(a * x / b) << '\\n';
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

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

  set<int> s;
  long long i, j;

  for (i = 1; i <= n; i++) {
    j = floor(a * i / b) - a * floor(i / b);
    s.insert(j);
  }
  auto it = s.end();
  cout << *--it;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

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


Error: TLE

Fixed submission:

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

#include <iostream>

int main() {
  long long A, B, N;
  long long ans = 0;

  std::cin >> A >> B >> N;

  ans = ((A * std::min(N, B - 1)) / B) - (A * (std::min(N, B - 1) / B));

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

Error: TLE

Fixed submission:

#include <iostream>
int main() {
  long long A, B, N;
  long long ans = 0;

  std::cin >> A >> B >> N;

  for (long long i = 1; i < B; i++) {
    if (i > N) {
      break;
    }
    long long tmp = ((A * i) / B) - (A * (i / B));
    //        std::cout << i  << "/" << tmp << std::endl;
    if (tmp > ans) {
      ans = tmp;
    }
  }

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

#include <bits/stdc++.h>

int ri() {
  int n;
  scanf("%d", &n);
  return n;
}

int main() {
  int a = ri();
  int64_t b, n;
  std::cin >> b >> n;

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

  int64_t res = 0;

  if (b <= 10000) {
    for (int i = 1; i < b && i <= n; i++)
      res = std::max(res, calc(i));
  } else {
    for (int i = 1;; i++) {
      int64_t x = (b * i - 1) / a + 1;
      if (x > n)
        break;
      res = std::max(res, calc(x));
    }
  }
  printf("%" PRId64 "\\n", res);
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

int ri() {
  int n;
  scanf("%d", &n);
  return n;
}

int main() {
  int a = ri();
  int64_t b, n;
  std::cin >> b >> n;
  if (n >= 1000000000) {
    assert(b != -1);
  }

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

  int64_t res = 0;
  for (int i = 1;; i++) {
    int64_t x = (b * i - 1) / a + 1;
    if (x > n)
      break;
    res = std::max(res, calc(x));
  }
  printf("%" PRId64 "\\n", res);
  return 0;
}