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;
  long long N;
  cin >> A >> B >> N;
  long long y = min(N, B - 1);
  long long maxVal = A * y / B;
  cout << maxVal << endl;
  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  long long A, B;
  long long N;
  cin >> A >> B >> N;
  long long maxVal = 0;
  long long y = min(N, B - 1);
  for (long long i = y; i >= 0; i--) {
    long long c = A * i / B;
    if (c > maxVal)
      maxVal = c;
  }
  cout << maxVal << endl;
  return 0;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define rep(i, s, n) for (int i = s; i < (int)(n); i++)
#define co(x) cout << x << endl
#define SQvec(i, j) vector<vector<int>> data(i, vector<int>(j))
#define mod 1000000000 + 7
typedef long long int lint;

int main() {
  lint A, B, N, ans, M;
  cin >> A >> B >> N;
  M = N - N % B - 1;
  ans = max((A * N) / B - A * (N / B), (A * M) / B - A * (M / B));
  co(ans);
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, s, n) for (int i = s; i < (int)(n); i++)
#define co(x) cout << x << endl
#define SQvec(i, j) vector<vector<int>> data(i, vector<int>(j))
#define mod 1000000000 + 7
typedef long long int lint;

int main() {
  lint A, B, N, ans;
  cin >> A >> B >> N;
  ans = (A * N) / B - A * (N / B);
  for (lint i = N - B; i <= N && (A * i) / B - A * (i / B) >= ans; i++) {
    if ((A * i) / B - A * (i / B) > ans) {
      ans = (A * i) / B - A * (i / B);
    }
  }
  co(ans);
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define REP(i, n) for (ll i = 0; i < n; i++)
#define REPR(i, n) for (ll i = n - 1; i >= 0; i--)

typedef long long ll;
#define INF 1e18

#define MOD 2019

int main() {
  long long int A, B, N;
  cin >> A >> B >> N;
  /*long long int max = -1000000000;
  int i = B-1;
  if(i > N){
      i = N;
  }
  while(i <= N){
      long long int temp = (A*i)/B - A * (i/B);
      if(temp > max){
          max = temp;
      }
      cout << temp << endl;
      i += B;
  }*/

  if (B <= 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 <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define REP(i, n) for (ll i = 0; i < n; i++)
#define REPR(i, n) for (ll i = n - 1; i >= 0; i--)

typedef long long ll;
#define INF 1e18

#define MOD 2019

int main() {
  long long int A, B, N;
  cin >> A >> B >> N;
  long long int max = -1000000000;
  int i = B - 1;
  if (i > N) {
    i = N;
  }
  while (i <= N) {
    long long int temp = (A * i) / B - A * (i / B);
    if (temp > max) {
      max = temp;
    }

    i += B;
  }

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

#include <iostream>
#include <math.h>
using namespace std;

int main() {

  long long A, B, N;
  cin >> A >> B >> N;

  long long tmp = 0;
  long long max_score = 0;

  long long maxC = floor(1.0 * N / B);
  //  cout << maxC << endl;

  if (B - 1 <= N) {
    N = B - 1;
  }

  tmp = floor(1.0 * A * N / B) - A * floor(N / B);
  if (tmp > max_score) {
    max_score = tmp;
  }

  cout << max_score;

  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
#include <math.h>
using namespace std;

int main() {

  long long A, B, N;
  cin >> A >> B >> N;

  long long tmp = 0;
  long long max_score = 0;

  long long maxC = floor(1.0 * N / B);
  //  cout << maxC << endl;
  for (int c = 0; c < maxC; c++) {
    //    if(maxC = 0)
    //   {
    //       tmp = floor(1.0*A*N/B) - A * floor(N/B);
    //    }else{
    //    cout << 1.0*A*(c+1-1.0/B) << " " << A*c << endl;
    //    tmp = floor(1.0*A*(c+1-1.0/B)) - A*c;
    tmp = floor(1.0 * A * ((c + 1) * (B - 1)) / B) - A * c;

    //    }
    if (tmp > max_score) {
      max_score = tmp;
    }
  }

  tmp = floor(1.0 * A * N / B) - A * floor(N / B);
  if (tmp > max_score) {
    max_score = tmp;
  }

  cout << max_score;

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

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

int main() {
  ll A, B, N, max = 0, x, y, ans;
  cin >> A >> B >> N;

  if (N <= 10000000000) {
    REP(i, N + 1) {
      y = i;
      ans = (A * y / B) - (A * (y / B));
      if (ans >= max) {
        max = ans;
      }
    }
  } else {

    REP(i, 1000000000000000000) {
      x = B * pow(10, i);
      y = x - 1;

      if (y > N) {
        break;
      }

      ans = (A * y / B) - (A * (y / B));

      if (ans >= max) {
        max = ans;
      }
    }
  }

  if (max == 0) {
    y = N - 1;
    ans = (A * y / B) - (A * (y / B));
    max = ans;
  }

  cout << max << endl;
}


Error: TLE

Fixed submission:

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

int main() {
  ll A, B, N, max = 0, x, y, ans;
  cin >> A >> B >> N;

  REP(i, 1000000000000000000) {
    x = B * pow(10, i);
    y = x - 1;

    if (y > N) {
      break;
    }

    ans = (A * y / B) - (A * (y / B));

    if (ans >= max) {
      max = ans;
    }
  }

  if (ans == 0) {
    REP(i, N + 1) {
      y = i;
      ans = (A * y / B) - (A * (y / B));
      if (ans >= max) {
        max = ans;
      }
    }
  }

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

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

template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int main(void) {
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);
  ll a, b, n;
  cin >> a >> b >> n;
  ll x = n;
  if (n >= b - 1)
    x = b - 1;
  ll ans = a * (x % b) / b;
  cout << ans << endl;

  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>

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

template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int main(void) {
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);

  ll a, b, n, ans;

  cin >> a >> b >> n;
  vector<pair<ll, ll>> k(b + 1);
  k[0].first = 0;
  k[0].second = 0;

  rep(i, b) {
    if (k[i].second + a >= b) {
      k[i + 1].first = k[i].first + (k[i].second + a) / b;
      k[i + 1].second = (k[i].second + a) % b;
    } else {
      k[i + 1].first = k[i].first;
      k[i + 1].second = k[i].second + a;
    }
  }
  ans = k[min(n, b - 1)].first;

  cout << ans << endl;

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

#include <algorithm>
#include <cmath>
#include <iostream>
#include <limits>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>

using namespace std;

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

  // int64_t ans = numeric_limits<int64_t>::min();
  // for(int x=0; x<=min(A, N); x++) {
  //     ans = max(ans, (A*x)/B - A*(x/B));
  // }

  // cout << ans << endl;
  int64_t x = min(B - 1, N);
  cout << (A * x) / B - A * (x / B) << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <limits>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>

using namespace std;

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

  int64_t ans = numeric_limits<int64_t>::min();
  for (int x = 0; x <= min(B, N); x++) {
    ans = max(ans, (A * x) / B - A * (x / 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 (long long i = 0; i < (long long)(n); i++)
#define rep2(i, s, n) for (long long i = (s); i < (long long)(n); i++)
#define repi(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2i(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(v) v.begin(), v.end()

using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;

const ll INF = (1LL << 60);
const int INFi = (1 << 29);

/*素数判定*/
bool is_prime(ll n) {
  if (n == 1)
    return false;
  for (ll i = 2; i * i <= n; i++) {
    if (n % i == 0)
      return false;
  }
  return true;
}

/*約数列挙*/
vll enum_divisors(ll n) {
  vll l;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      l.push_back(i);
      if (n / i != i)
        l.push_back(n / i);
    }
  }
  sort(all(l));
  return l;
}

/*素因数分解*/
vector<P> prime_factorize(ll n) {
  vector<P> l;
  for (ll i = 2; i * i <= n; i++) {
    if (n % i != 0)
      continue;
    ll e = 0;
    while (n % i == 0) {
      e++;
      n /= i;
    }
    l.push_back({i, e});
  }
  if (n != 1)
    l.push_back({n, 1});
  return l;
}

int main() {

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

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

  return 0;
}

Error: TLE

Fixed submission:

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

#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
#define rep2(i, s, n) for (long long i = (s); i < (long long)(n); i++)
#define all(v) v.begin(), v.end()

using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;

const ll INF = (1LL << 60);

int main() {

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

  ll m = 0;
  for (ll x = n - n / 4; x <= n; x++) {
    m = max(a * x / b - a * (x / b), m);
  }

  cout << m << endl;

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

#include <cmath>
#include <iomanip>
#include <iostream>
#include <stdint.h>
using namespace std;

#define int long long

int32_t main() {
  //	cout << fixed << setprecision(25);
  // int t;

  // cin >> t;

  //	while(t--){

  int A, B, N;

  cin >> A >> B >> N;

  double x = min(B - 1, N);

  double ans = floor((A * x) / B) - A * floor(x / B);

  cout << ans << endl;

  //	}
}

Error: TLE

Fixed submission:

#include <cmath>
#include <iomanip>
#include <iostream>
#include <stdint.h>
using namespace std;

#define int long long

int32_t main() {
  //	cout << fixed << setprecision(25);
  // int t;

  // cin >> t;

  //	while(t--){

  int A, B, N;

  cin >> A >> B >> N;
  double ans = 0;
  for (int x = 0; x <= N; x++) {

    double tmp = floor((A * x) / B) - A * floor(x / B);

    ans = max(tmp, ans);
  }

  cout << ans << endl;

  //	}
}
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 num;
  if (B - 1 > N) {
    num = N;
  } else {
    num = B - 1;
  }
  long long f = ((A * num) / B) - A * (num / B);
  cout << f << endl;
}


Error: TLE

Fixed submission:

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

int main() {
  long long A, B, N;
  cin >> A >> B >> N;
  long long num = 1, max = 0;
  for (num = 1; num <= B - 1 && num <= N; num++) {
    int f = ((A * num) / B) - A * (num / B);
    if (f > max) {
      max = f;
    }
  }
  cout << max << endl;
}
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 all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
typedef long long ll;
#define _GLIBCXX_DEBUG
typedef vector<int> vec;
typedef vector<ll> lvec;
typedef vector<char> cvec;
typedef vector<double> dvec;
typedef pair<ll, ll> LP;
typedef tuple<ll, ll, ll> LT;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
#define fs first
#define sc second

int main() {
  ll a, b, n;
  cin >> a >> b >> n;
  ll c;
  if (n > b - 1)
    c = b - 1;
  else
    c = n;
  ll ans = a * (c % b) / b;
  cout << ans << 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 all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
typedef long long ll;
#define _GLIBCXX_DEBUG
typedef vector<int> vec;
typedef vector<ll> lvec;
typedef vector<char> cvec;
typedef vector<double> dvec;
typedef pair<ll, ll> LP;
typedef tuple<ll, ll, ll> LT;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
#define fs first
#define sc second
ll f(ll a, ll b, ll x) {
  ll p = (a * x - (a * (x % b) % b)) / b;
  ll q = (x - x % b) / b;
  return p - a * q;
}
int main() {
  ll a, b, n;
  cin >> a >> b >> n;
  ll c;
  if (n > b)
    c = n - b;
  else
    c = n;
  ll ans = -1;
  for (ll x = 1; x <= c; x++) {
    ll F = f(a, b, x);
    ans = max(F, ans);
  }
  cout << ans << endl;
}
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 i = min(b - 1, n);
  long long max = a * i / b;

  cout << max << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  long long a, b, n;
  cin >> a >> b >> n;
  long max = 0;
  for (int i = 1; i < b && i <= n; i++) {
    long k = a * i / b;
    if (max < k)
      max = k;
  }

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

#include <bits/stdc++.h>
// Begin Header {{{
#define all(x) (x).begin(), (x).end()
#define lli long long int
#define rep(i, n) for (lli i = 0; i < n; i++)
#define loop(i, j, n) for (lli i = j; i < n; i++)
#define Max(a, b) ((a) > (b) ? (a) : (b))
#define Min(a, b) ((a) < (b) ? (a) : (b))
constexpr int INF = 0x3f3f3f3f;
const long long mod = 1e9 + 7;
// Function
lli combi(lli n, lli r) {
  if (r == 0 || r == n)
    return 1;
  else
    return combi(n - 1, r) + combi(n - 1, r - 1);
}
lli sigma1(lli n) { return n * (n + 1) / 2; }
lli sigma2(lli s, lli n) { return sigma1(n) - sigma1(s - 1); }
using namespace std;
// }}} End Header

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  lli a, b, n;
  cin >> a >> b >> n;
  lli t = Min(n, b - 1);
  lli ans = (a * t) / b - a * (t / b);
  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
// Begin Header {{{
#define all(x) (x).begin(), (x).end()
#define lli long long int
#define rep(i, n) for (lli i = 0; i < n; i++)
#define loop(i, j, n) for (lli i = j; i < n; i++)
#define Max(a, b) ((a) > (b) ? (a) : (b))
#define Min(a, b) ((a) < (b) ? (a) : (b))
constexpr int INF = 0x3f3f3f3f;
const long long mod = 1e9 + 7;
// Function
lli combi(lli n, lli r) {
  if (r == 0 || r == n)
    return 1;
  else
    return combi(n - 1, r) + combi(n - 1, r - 1);
}
lli sigma1(lli n) { return n * (n + 1) / 2; }
lli sigma2(lli s, lli n) { return sigma1(n) - sigma1(s - 1); }
using namespace std;
// }}} End Header
inline lli floor(double a, double b, double x) {
  lli h, p;
  h = (lli)(a * x / b);
  p = (lli)(x / b);
  return h - p;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  lli c, d, n;
  lli ans = 0;
  cin >> c >> d >> n;
  loop(i, 1, n + 1) {
    lli sub;
    if (i % d == 0) {
      sub = 0;
    } else {
      sub = floor((double)c, (double)d, (double)i);
      if (ans < sub)
        ans = sub;
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

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

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


Error: TLE

Fixed submission:

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

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

#include <iostream>

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for (ll i = ll(a); i <= ll(b); ++i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)

using namespace std;
using ll = long long;

int main() {

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

  ll max = 0;
  ll x = (n >= b) ? b - 1 : n;
  max = ((a * x) / b) - a * (x / b);
  //     repi(x,1,b-1){
  // //        if((a*x)%b != 0) continue;
  //         ll t =((a * x)/b) - (a * (x/b));
  //         printf("t:%d\\n",t);
  //         if(t > max){
  //             max = t;
  //         }
  //     }

  cout << max << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for (ll i = ll(a); i <= ll(b); ++i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)

using namespace std;
using ll = long long;

int main() {

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

  ll max = 0;
  if (b < n) {
    repi(x, 1, b) {

      ll t = ((a * x) / b) - (a * (x / b));
      if (t > max) {
        max = t;
      }
    }
  } else {
    repi(x, 1, n) {

      ll t = ((a * x) / b) - (a * (x / b));
      if (t > max) {
        max = t;
      }
    }
  }

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

// #include <bits/stdc++.h>
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string.h>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define ff first
#define ss second
#define ll long long
#define mod 998244353
using namespace std;
ll a, b, n, ans;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> a >> b >> n;
  ll x = min(b - 1, n);
  ans = a * x / b - a * (x / b);
  cout << ans;
}
/*
 2
 1 1
 1 0
 1 1
 1 1
 */


Error: TLE

Fixed submission:

// #include <bits/stdc++.h>
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string.h>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define ff first
#define ss second
#define ll long long
#define mod 998244353
using namespace std;
ll a, b, n, ans;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> a >> b >> n;
  for (ll i = 1; i <= n; i++) {
    ll cur = a * i / b - a * (i / b);
    //        cout<<i<<" "<<cur<<endl;
    if (cur < ans)
      break;
    ans = max(ans, cur);
  }
  cout << ans;
}
/*
 2
 1 1
 1 0
 1 1
 1 1
 */
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <vector>

using namespace std;

int main(int, const char **) {
  long long A, B, N;
  cin >> A >> B >> N;
  long long x = N;
  if (N > B - 1) {
    x = B - 1;
  }

  long long ans = (A * x) / B - A * (x / B);

  cout << ans << endl;

  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>

int main(int argc, const char *argv[]) {
  long long A, B, N, max = 0;
  std::cin >> A >> B >> N;

  for (long long i = 1; i <= N; i++) {
    long long temp = (A * i) / B - (A * (i / B));
    if (max < temp) {
      max = temp;
    }
  }

  // insert code here...
  std::cout << max;

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

#include <bits/stdc++.h>

#define REP(i, x) REPI(i, 0, x)
#define REPI(i, a, b) for (int i = int(a); i < int(b); ++i)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
using namespace std;

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

  long double A, B, N;
  cin >> A >> B >> N;
  // long double ans = 0;
  long double a_b = A / B;

  // long double prev_ans = -1;
  // for (long double x = 1.0; x <= N; x += 1.0) {
  //   ans = max(ans, floor(a_b * x) - A * floor(x / B));
  //   // if (prev_ans != -1) {
  //   //   if (prev_ans > ans) {
  //   //     cout << ans << endl;
  //   //     return 0;
  //   //   }
  //   // }
  //   prev_ans = ans;

  //   cout << setprecision(5) << floor(a_b * x) << ":" << A * floor(x / B)
  //        << endl;
  // }

  long double x = min(N, B - 1);
  cout << floor(a_b * x) - A * floor(x / B) << endl;

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

#define REP(i, x) REPI(i, 0, x)
#define REPI(i, a, b) for (int i = int(a); i < int(b); ++i)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
using namespace std;

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

  long double A, B, N;
  cin >> A >> B >> N;
  long double ans = 0;
  long double a_b = A / B;

  long double prev_ans = -1;
  for (long double x = 1.0; x <= N; x += 1.0) {
    ans = max(ans, floor(a_b * x) - A * floor(x / B));
    if (prev_ans != -1) {
      if (prev_ans > ans) {
        cout << ans << endl;
        return 0;
      }
    }
    prev_ans = ans;

    // cout << setprecision(5) << floor(A * x / B) - A * floor(x / B) << endl;
  }

  cout << ans << endl;

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

#include <cmath>
#include <iostream>
#include <vector>

using namespace std;
typedef long long ll;

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

  ll ans = 0;
  if (B == 1) {
    ans = 0;
  } else if (N < B) {
    ll a = floor(A * N / B);
    ll b = floor(N / B);
    ans = a - A * b;
  } else {
    ll a = floor(A * (B - 1) / B);
    ll b = floor((B - 1) / B);
    ans = a - A * b;
  }

  cout << ans << endl;
  /*
  ll ans2=0;


  for(int x=1;!(x%B==0)&&(x<=N);++x){
      ll a=(A*(x))/B;
      ll b=(x)/B;
      ll c=a-A*b;
      //cout<<"x:"<<x<<" a:"<<a<<" "<<"-A*x/B:"<<A*b<<" ans:"<<ans<<endl;
      ans2=ans2>=c?ans2:c;
  }

  cout<<"ans2: "<<ans2<<endl;
   */
}


Error: TLE

Fixed submission:


#include <iostream>

#include <vector>

using namespace std;
typedef long long ll;

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

  ll ans = 0;
  for (int x = 1; !(x % B == 0) && (x <= N); ++x) {
    ll a = (A * (x)) / B;
    ll b = (x) / B;
    ll c = a - A * b;
    // cout<<"x:"<<x<<" a:"<<a<<" "<<"-A*x/B:"<<A*b<<" ans:"<<ans<<endl;
    ans = ans >= c ? ans : c;
  }

  cout << ans << endl;
}