alexjercan/bugnet huggingface dataset:
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, ans, x;
  cin >> a >> b >> n;
  x = min(b - 1, n);
  ans = a * x / b - a * (x / b);
  cout << ans << endl;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <stack>
#include <string>
#include <vector>

typedef long long ll;

using namespace std;

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

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

ll a, b, n;

ll f(ll x) {
  ll A = floor(a * x / b);
  // cout << A << endl;
  ll B = floor(x / b);
  return A - a * B;
}

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


Error: TLE

Fixed submission:

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

ll a, b, n;

ll f(ll x) {
  ll A = floor(a * x / b);
  // cout << A << endl;
  ll B = floor(x / b);
  return A - a * B;
}

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

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <math.h>
#include <string.h>
#include <vector>
using namespace std;

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

  cin >> a >> b >> n;

  long long minv = min(b - 1, n);

  printf("%lld\\n", a * minv / b - a * (minv / b));

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <string.h>
#include <vector>
using namespace std;

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

  cin >> a >> b >> n;

  long long maxv = 0;

  for (long long x = 1; x <= n; x++) {
    maxv = max((a * x) / b - a * (x / b), maxv);
  }

  printf("%lld\\n", maxv);

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

#include <algorithm>
#include <iostream>

using namespace std;

int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long int A, B, N, i, j, ans = 0;
  cin >> A >> B >> N;
  ans = (N >= B - 1) ? A * (B - 1) / B - A * ((B - 1) / B)
                     : (A * N / B - A * (N / B));
  cout << ans << '\\n';
  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>

using namespace std;

int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long int A, B, N, i, j, ans = 0;
  cin >> A >> B >> N;
  if (N >= B - 1) {
    for (i = B - 1; i <= N; i += B)
      ans = (ans, A * i / B - A * (i / B));
  } else
    ans = (A * N / B - A * (N / B));
  cout << ans << '\\n';
  return 0;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

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

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

  ll x = b - 1;
  if (n < b - 1)
    x = n;
  ll ans = floor(a * (x % b) / b);

  cout << ans << endl;

  return 0;
}


Error: TLE

Fixed submission:

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

ll lmax(ll p, ll q) {
  if (p > q)
    return p;
  else
    return q;
}

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

  ll dp = floor(0) - a * floor(0);

  do {
    ll x = n;
    ll comp = floor(a * x / b) - a * floor(x / b);
    if (comp < 0)
      x /= 2;
    else {
      ll k = x;
      for (ll f = 1; f <= k; f++) {
        comp = floor(a * f / b) - a * floor(f / b);
        dp = lmax(dp, comp);
      }
      break;
    }
  } while (1);

  cout << dp << endl;

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

#include <iostream>
using namespace std;

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

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int f(long long a, long long b, long long x) {
  long long s = a * x / b;
  long long t = a * (x / b);
  return s - t;
}
int main() {
  long long a, b, n;
  cin >> a >> b >> n;
  long long ans = 0;
  for (long long i = n / 2; i <= n; i++) {
    if (ans < f(a, b, i))
      ans = f(a, b, i);
  }
  cout << ans << endl;
}
Problem p02696 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define f first
#define s second
#define pb push_back
#define eb emplace_back
#define mk make_pair
#define mt make_tuple
#define MOD 1000000007
#define fo(i, a, b) for (i = a; i < b; i++)
#define foe(i, a, b) for (i = a; i <= b; i++)
#define all(x) x.begin(), x.end()
#define vi vector<int>
#define vl vector<long long int>
#define pii pair<int, int>
#define pll pair<long long int, long long int>
#define vpii vector<pair<int, int>>
#define vpll vector<pair<long long int, long long int>>
#define boost                                                                  \\
  ios::sync_with_stdio(false);                                                 \\
  cin.tie(0)
using namespace std;
const int inf = 1e9 + 5;
const ll inf64 = 1e18 + 5;
int main() {
  boost;
  ll a, b, n;
  cin >> a >> b >> n;
  ll ans = 0;
  if (b == 1)
    ans = 0;
  else if (b > n)
    ans = (a * n) / b;
  else {
    ll x = n / (b - 1);
    x *= (b - 1);
    ans = (a * x) / b - a * (x / b);
  }
  cout << ans;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define f first
#define s second
#define pb push_back
#define eb emplace_back
#define mk make_pair
#define mt make_tuple
#define MOD 1000000007
#define fo(i, a, b) for (i = a; i < b; i++)
#define foe(i, a, b) for (i = a; i <= b; i++)
#define all(x) x.begin(), x.end()
#define vi vector<int>
#define vl vector<long long int>
#define pii pair<int, int>
#define pll pair<long long int, long long int>
#define vpii vector<pair<int, int>>
#define vpll vector<pair<long long int, long long int>>
#define boost                                                                  \\
  ios::sync_with_stdio(false);                                                 \\
  cin.tie(0)
using namespace std;
const int inf = 1e9 + 5;
const ll inf64 = 1e18 + 5;
int main() {
  boost;
  ll a, b, n;
  cin >> a >> b >> n;
  ll ans = 0;
  if (b > n)
    ans = (a * n) / b;
  else {
    ll x = n / (b - 1);
    x *= (b - 1);
    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;
typedef long long ll;

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = (ll)(n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define FORD(i, a, b) for (ll i = (a); i >= (b); i--)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define SUM(x) accumulate(ALL(x), 0)
#define INF 1000000000000
#define MOD 10000007
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define MAXR 100000

ll solve(ll &a, ll &b, ll &x) {
  ll res = (int)(a * x / b) - a * (int)(x / b);
  return res;
}

int main() {
  ll a, b, n;
  cin >> a >> b >> n;
  // ll x = b / a + 1;
  // ll y = min(n, b);
  // cout << max(solve(a, b, x), solve(a, b, y)) << endl;

  ll a_ = 0;
  if (b <= n)
    a_ = b - 1;
  else
    a_ = n;
  cout << solve(a, b, a_) << endl;

  // ll ans = 0;
  // for (ll i = x; i <= min(b, n); i ++) {
  //   ans = max(ans, solve(a, b, i));
  // }
  // cout << ans << endl;

  // ll x = n;
  // if (a < b) {
  //   if (b <= x) {
  //     ll u = b - 1;
  //     cout << solve(a, b, u) << endl;
  //   } else cout << solve(a, b, n) << endl;
  // } else {
  //   if (b <= x) {
  //     ll y = b - 1;
  //     if (solve(a, b, x) < solve(a, b, y)) cout << solve(a, b, y) << endl;
  //     else cout << solve(a, b, x) << endl;
  //   }
  //   else cout << solve(a, b, x) << endl;
  // }
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = (ll)(n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define FORD(i, a, b) for (ll i = (a); i >= (b); i--)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define SUM(x) accumulate(ALL(x), 0)
#define INF 1000000000000
#define MOD 10000007
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define MAXR 100000

ll solve(ll &a, ll &b, ll &x) {
  ll res = (int)(a * x / b) - a * (int)(x / b);
  return res;
}

int main() {
  ll a, b, n;
  cin >> a >> b >> n;
  ll x = b / a + 1;
  ll ans = 0;
  for (ll i = x; i <= min(b, n); i++) {
    ans = max(ans, solve(a, b, i));
  }
  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, M, Ma = 0;
  cin >> A >> B >> N;
  if (B - 1 >= N)
    cout << floor(A * N / B) - A * floor(N / B) << endl;
  else
    cout << floor((A * (B - 1)) / B) - A * floor((B - 1) / B) << endl;
}


Error: TLE

Fixed submission:

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

int main() {
  long long A, B, N, M, Ma;
  cin >> A >> B >> N;
  for (int i = B - 1; i <= N; i += B) {
    M = floor(A * i / B) - A * floor(i / B);
    if (Ma < M) {
      Ma = M;
    }
  }
  M = floor(A * N / B) - A * floor(N / B);
  if (Ma < M) {
    Ma = M;
  }
  cout << Ma << endl;
}
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 < (n); ++i)
#define REP(i, d, n) for (long long i = (d); i < (n); ++i)
#define all(v) v.begin(), v.end()
using ll = long long;
int main() { // 言語変えろ言語変えろ言語変えろ言語変えろ言語変えろ

  ll a, b, n;
  cin >> a >> b >> n;
  ll max = -999999;
  ll ans;

  if (b > n) {
    ans = n;
  } else {
    ans = b - 1;
  }

  max = ans * a / b - a * (ans / b);

  cout << max << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (long long i = 0; i < (n); ++i)
#define REP(i, d, n) for (long long i = (d); i < (n); ++i)
#define all(v) v.begin(), v.end()
using ll = long long;
int main() { // 言語変えろ言語変えろ言語変えろ言語変えろ言語変えろ

  ll a, b, n;
  cin >> a >> b >> n;
  ll max = -999999;
  ll ans;

  rep(i, n) {
    if (n - i < b) {
      ans = n - i;
      break;
    }
  }

  max = ans * a / b - a * (ans / b);

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

#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
const long long mod = 1e9 + 7;
int main() {
  ll a, b, n;
  cin >> a >> b >> n;
  cout << a * min(n, b - 1) / b;
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
const long long mod = 1e9 + 7;
int main() {
  ll a, b, n;
  cin >> a >> b >> n;
  ll max = 0;
  for (ll i = 0; i <= min(b - 1, n); i++) {
    if ((a * i) / b > max) {
      max = (a * i) / b;
    }
  }
  cout << max;
  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 (ll i = 0; i < (ll)(n); i++)
ll ans = 0;

int main() {
  ll a, b, n;
  cin >> a >> b >> n;
  ll k = min(b - 1, n);
  ans = max(ans, (a * k) / b - a * (k / b));
  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

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

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

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

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

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

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

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

int main() {
  long long int a, b, n, v, i, max, tmp;
  scanf("%lld %lld %lld", &a, &b, &n);
  max = 0;
  if (n < b) {
    max = floor(a * n * 1.00 / b);
  } else {
    max = floor(a * (b - 1) * 1.00 / b);
  }
  printf("%lld\\n", max);
  return 0;
}


Error: TLE

Fixed submission:

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

int main() {
  long long int a, b, n, v, i, max, tmp;
  scanf("%lld %lld %lld", &a, &b, &n);
  max = 0;
  for (i = 1; i <= n && i <= b * 2; i++) {
    v = floor(a * i * 1.00 / b) - a * floor(i / b);
    if (v > max)
      max = v;
  }
  printf("%lld\\n", max);
  return 0;
}
Problem p02696 (C++) — buggy submission, verdict: Runtime Error

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

#define rep(i, n) for (ll i = 0; i < n; i++)
#define all(v) v.begin(), v.end()
#define vec vector

/*  <<bit全探索>>

    for (int tmp = 0; tmp < (1 << ビット数); tmp++) {
        bitset<ビット数> s(tmp);
    }
*/

/*　<<stringで読み込んだ数列を一桁ずつint型へ変換>>

    string str;
    int N[桁数];

    cin >> str;

    for (int i = 0; i < 桁数; ++i) {

        N[i] = (int)(str[i] - '0');  //str[i]　はchar型なのでchar→intへ変換

        //cout << N[i] << endl;  //確認のため表示
    }
*/

typedef long long ll;

///////////////////////////////////////////////////////////////////////////

int main() {

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

  int f, g;

  f = floor(A * (B - 1) / B) - A * floor((B - 1) / B);

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


Error: WA

Fixed submission:

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

#define rep(i, n) for (ll i = 0; i < n; i++)
#define all(v) v.begin(), v.end()
#define vec vector

/*  <<bit全探索>>

    for (int tmp = 0; tmp < (1 << ビット数); tmp++) {
        bitset<ビット数> s(tmp);
    }
*/

/*　<<stringで読み込んだ数列を一桁ずつint型へ変換>>

    string str;
    int N[桁数];

    cin >> str;

    for (int i = 0; i < 桁数; ++i) {

        N[i] = (int)(str[i] - '0');  //str[i]　はchar型なのでchar→intへ変換

        //cout << N[i] << endl;  //確認のため表示
    }
*/

typedef long long ll;

///////////////////////////////////////////////////////////////////////////

int main() {

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

  vec<ll> S(N + 1, 0);

  for (int i = 1; i <= N; i++) {
    S.at(i) = floor(A * (i + 1) / B) - A * floor((i + 1) / B);
    if (S.at(i) < S.at(i - 1)) {
      S.at(i) = S.at(i - 1);
    }
  }

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

#include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <vector>
using namespace std;

int main() {
  long long int a, b, n, max = INT_MIN, ans, x;
  cin >> a >> b >> n;
  if (a < b) {
    x = n - 1;
    ans = floor((a * x) / b) - (a * (floor(x / b)));
    if (ans > max) {
      max = ans;
    }
  } else if (b != n) {
    x = n;
    ans = floor((a * x) / b) - (a * (floor(x / b)));
    if (ans > max) {
      max = ans;
    }
  } else {
    x = n - 1;
    ans = floor((a * x) / b) - (a * (floor(x / b)));
    if (ans > max) {
      max = ans;
    }
  }
  if (n > b) {
    x = b - 1;
    ans = floor((a * x) / b) - (a * (floor(x / b)));
    if (ans > max) {
      max = ans;
    }
  }
  cout << max << endl;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <vector>
using namespace std;

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

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

typedef long long ll;
const int maxn = 100005;
typedef pair<int, int> par;
const ll mod = 1e9 + 7;

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

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
#ifdef acm
  freopen("a.in", "r", stdin);
#endif // acm

  cin >> a >> b >> n;

  //    for( int i = 0; i <= 20; i++ )
  //        cout << f(i) << '\\n';

  //    ll ini = b/a;
  //    if( f(ini) == 0 )
  //        ini++;
  //
  //    ll sol = 0;
  //    for( ll i = ini; i <= n; i++ ){
  //        sol = max(sol, f(i));
  //        if( !f(i) )break;
  //    }

  ll sol = f(min(n, b - 1));
  cout << sol << "\\n";
  return 0;
}


Error: TLE

Fixed submission:

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

typedef long long ll;
const int maxn = 100005;
typedef pair<int, int> par;
const ll mod = 1e9 + 7;

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

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
#ifdef acm
  freopen("a.in", "r", stdin);
#endif // acm

  cin >> a >> b >> n;

  ll ini = b / a;
  if (f(ini) == 0)
    ini++;

  ll sol = 0;
  for (ll i = ini; i <= n; i++) {
    sol = max(sol, f(i));
    if (!f(i))
      break;
  }

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

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

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

  ll max = 0;
  /*
  for(ll i = N; i > 0; i--){
      if()
      ll tmp = floor((A * i)/B) - A*floor(i/B);
      if(tmp > max){
          max = tmp;
      }
  }
  */
  ll tmp = floor((A * N) / B) - A * floor(N / B);
  if (tmp > max) {
    max = tmp;
  }

  if (N >= (B - 1)) {
    ll tmp2 = 0;
    tmp2 = floor((A * (B - 1)) / B) - A * floor((B - 1) / B);

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

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

Error: TLE

Fixed submission:

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

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

  ll max = 0;
  for (ll i = N; i >= 0; i--) {
    ll tmp = floor((A * i) / B) - A * floor(i / B);
    if (tmp > max) {
      max = tmp;
    }
  }

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

// g++ -std=gnu++14 a.cpp
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iomanip>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>

using namespace std;

#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
ll MOD = 1e9 + 7;
int INF = 1 << 30;
ll INFL = 1LL << 60;

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

    ll i = B - 1;
    // while(i <= N){
    ll tmp = 0;
    tmp = (A * i) / B - A * (i / B);
    ans = max(ans, tmp);
    //  i += B;
    //}
  }
  cout << ans << endl;
}


Error: TLE

Fixed submission:

// g++ -std=gnu++14 a.cpp
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iomanip>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>

using namespace std;

#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
ll MOD = 1e9 + 7;
int INF = 1 << 30;
ll INFL = 1LL << 60;

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

    ll i = B - 1;
    while (i <= N) {
      ll tmp = 0;
      tmp = (A * i) / B - A * (i / B);
      ans = max(ans, tmp);
      i += B;
    }
  }
  cout << ans << endl;
}
Problem p02696 (C++) — buggy submission, verdict: Runtime Error

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

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

  long long int result1, result2, result3;
  result1 = (A * N) / B;
  // result2 = (A*N)/B-A*(N/B);
  result3 = (A * (B - 1)) / B;

  cout << min(result1, result3) << endl;
}


Error: 0

Fixed submission:

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

int main() {
  long long int A, B, N;
  cin >> A >> B >> N;
  long long int a, aa;
  a = A / B;
  aa = A % B;

  long long int result1, result2 = 0;
  result1 = (A * N) / B;
  if (N + 1 > B) {
    vector<long long int> t(N - B + 1);
    for (long long int i = 0; i < N - B + 1; i++) {
      long long int tmp1, tmp2;
      tmp1 = (B + i) / B;
      tmp2 = (B + i) % B;
      t.at(i) = a * (tmp2 - tmp1) * B + a * tmp2 + (aa * tmp2) / B * B;
      // cout << i << ":" << t.at (i)<< endl;
    }

    sort(t.begin(), t.end());
    result2 = t.at(N - B);
  }
  cout << (result1 > result2 ? result1 : result2) << endl;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <string>
#include <vector>

using ll = long long;

ll floar(long double t) { return t / 1; }

int main() {
  ll a, b, n;
  std::cin >> a >> b >> n;
  ll maxVal = 0;
  if (n / b >= 1) {
    maxVal = (a * (b - 1)) / b;
  } else {
    maxVal = (a * n) / b;
  }

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


Error: TLE

Fixed submission:

#include <iostream>
#include <string>
#include <vector>

using ll = long long;

ll floar(long double t) { return t / 1; }

int main() {
  ll a, b, n;
  std::cin >> a >> b >> n;
  ll maxVal = 0;
  if (n / b >= 1) {
    for (int i = 0; i < b; i++) {
      maxVal = std::max(maxVal, (a * i) / b);
    }
  } else {
    for (int i = 0; i <= n; i++) {
      maxVal = std::max(maxVal, (a * i) / b);
    }
  }

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