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

#include <cmath>
#include <iostream>
#define REP(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;

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

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

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

  ll x;
  if (n < b - 1)
    x = n;
  else
    x = b - 1;

  ll ans = floor(a * (x % b) / b);

  cout << ans << '\\n';
  return 0;
}


Error: TLE

Fixed submission:

#include <cmath>
#include <iostream>
#define REP(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;

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

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

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

  ll ans = 0;
  for (int i = 1; i <= n; i++) {
    ll tmp = floor(a * i / b) - a * floor(i / b);
    chmax(ans, tmp);
  }

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

//
//  header_useful.h
//  c++_acm
//
//  Created by 李弘辰 on 2019/7/23.
//  Copyright © 2019 李弘辰. All rights reserved.
//

#include <algorithm> // sort
#include <bitset>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <utility> // pair
#include <vector>

using namespace std;

#define ll long long
#define uchar unsigned char
#define ushort unsigned short
#define uint unsigned int
#define ulong unsigned long
#define ull unsigned long long

#define INT_INF 0x7fffffff

#define pi acos(-1)

#define mx(a, b) (a) > (b) ? (a) : (b)
#define mn(a, b) (a) < (b) ? (a) : (b)
#define mem(a, b) memset(a, b, sizeof(a))
#define fre(a) freopen(a, "r", stdin)

#define cio                                                                    \\
  ios::sync_with_stdio(false); // Do not use it with "scanf" and other c input!

#define itn int
#define nit int
#define inr int
#define mian main
#define ednl endl
#define fro for
#define fir for
#define reutrn return
#define retunr return
#define reutnr return

/* header_useful_h */

int main() {
  ll a, b, n;
  scanf("%lld%lld%lld", &a, &b, &n);
  ll x;
  if (b <= n)
    x = b - 1;
  else
    x = n;
  printf("%lld\\n", a * x / b - a * (x / b));
  return 0;
}


Error: TLE

Fixed submission:

//
//  header_useful.h
//  c++_acm
//
//  Created by 李弘辰 on 2019/7/23.
//  Copyright © 2019 李弘辰. All rights reserved.
//

#include <algorithm> // sort
#include <bitset>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <utility> // pair
#include <vector>

using namespace std;

#define ll long long
#define uchar unsigned char
#define ushort unsigned short
#define uint unsigned int
#define ulong unsigned long
#define ull unsigned long long

#define INT_INF 0x7fffffff

#define pi acos(-1)

#define mx(a, b) (a) > (b) ? (a) : (b)
#define mn(a, b) (a) < (b) ? (a) : (b)
#define mem(a, b) memset(a, b, sizeof(a))
#define fre(a) freopen(a, "r", stdin)

#define cio                                                                    \\
  ios::sync_with_stdio(false); // Do not use it with "scanf" and other c input!

#define itn int
#define nit int
#define inr int
#define mian main
#define ednl endl
#define fro for
#define fir for
#define reutrn return
#define retunr return
#define reutnr return

/* header_useful_h */

ll gcd(ll a, ll b) {
  if (a % b == 0)
    return b;
  return gcd(b, a % b);
}

int main() {
  ll a, b, n;
  scanf("%lld%lld%lld", &a, &b, &n);
  n = min(n, b - gcd(a, b) + 1);
  double mx = -1e13;
  double mx_x;
  double A = a, B = b;
  for (double x = 0; x <= n; x++) {
    double p = floor(A * x / B) - a * floor(x / B);
    if (p > mx) {
      mx = p;
      mx_x = x;
    }
  }
  printf("%.0lf\\n", mx);
  return 0;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> ii;
typedef vector<ll> vi;
typedef long double ld;
const ll INF = (ll)1e18;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define INF ll(1e18)
#define MOD 1000000007
#define print(a)                                                               \\
  ;                                                                            \\
  for (auto x : a)                                                             \\
    cout << x << " ";                                                          \\
  cout << "\\n";
#define mset(a)                                                                \\
  ;                                                                            \\
  memset(a, 0, sizeof(a));

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  ll a, b, n;
  cin >> a >> b >> n;
  ll j = min(b - 1, n);
  cout << a * j / b - a * (j / b) << "\\n";
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> ii;
typedef vector<ll> vi;
typedef long double ld;
const ll INF = (ll)1e18;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define INF ll(1e18)
#define MOD 1000000007
#define print(a)                                                               \\
  ;                                                                            \\
  for (auto x : a)                                                             \\
    cout << x << " ";                                                          \\
  cout << "\\n";
#define mset(a)                                                                \\
  ;                                                                            \\
  memset(a, 0, sizeof(a));

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  ll a, b, n;
  cin >> a >> b >> n;
  ll Max = -INF;
  for (ll i = 1; i <= n; i++) {
    ll d1 = (ll)((ld)(a * i) / b);
    ll d2 = (ll)i / b;
    Max = max(Max, d1 - a * d2);
  }
  cout << Max << "\\n";
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;
const int mod = 1e9 + 7;

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

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

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;
const int mod = 1e9 + 7;

int main() {
  ll A, B, N;
  cin >> A >> B >> N;
  ll xmod = 0, mx = 0, mn;

  mn = (floor(N / B) - 1) * B;

  for (ll i = N; i > mn; --i) {
    mx = floor(A * i / B) - A * floor(i / B);
    xmod = max(xmod, mx);
  }

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

// I'm a f*cking looser
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fasino                                                                 \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);
#define asc(A) sort(A.begin(), A.end())
#define dsc(A) sort(A.begin(), A.end(), greater<ll>())
#define input(A, N)                                                            \\
  for (ll i = 0; i < N; i++)                                                   \\
    cin >> A[i];
int main() {
  fasino
#ifndef ONLINE_JUDGE
// freopen("input.txt", "r", stdin);
#endif
      ll a,
      b, n;
  cin >> a >> b >> n;
  ll maxi = INT32_MIN;
  // for(int i=;i<min(b,n);i++){
  // ll i=b;
  maxi = floor(double(a * (min(b, n) - 1)) / b) -
         (a * floor(double(min(b, n) - 1) / b));
  ll k =
      floor(double(a * (min(b, n))) / b) - (a * floor(double(min(b, n)) / b));
  maxi = max(maxi, k);
  // if(b==1){
  //     maxi = floor(double(a*n)/b)-(a*floor(double(n))/b);
  // }
  // maxi = max(maxi,m);
  //
  // }
  cout << maxi;
  return 0;
}

Error: TLE

Fixed submission:

// I'm a f*cking looser
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fasino                                                                 \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);
#define asc(A) sort(A.begin(), A.end())
#define dsc(A) sort(A.begin(), A.end(), greater<ll>())
#define input(A, N)                                                            \\
  for (ll i = 0; i < N; i++)                                                   \\
    cin >> A[i];
int main() {
  fasino
#ifndef ONLINE_JUDGE
// freopen("input.txt", "r", stdin);
#endif
      ll a,
      b, n;
  cin >> a >> b >> n;
  ll maxi = INT32_MIN;
  for (int i = 1; i <= min(b, n); i++) {
    // ll i=b;
    ll m = floor(double(a * i) / b) - (a * floor(double(i) / b));
    maxi = max(maxi, m);
  }
  cout << maxi;
  return 0;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#include "bits/stdc++.h"

using namespace std;

#define sp(x) cout << setprecision(x);
#define all(a) (a).begin(), (a).end()
#define inf 10000000
#define linf INT64_MAX * 0.99
#define int long long
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define yes "Yes"
#define no "No"
#define divs 1000000007
#define dive 1000000009
#define pi 3.141592653589793238

typedef pair<int, int> P;

signed main() {
  // ios::sync_with_stdio(false);
  // cin.tie(0);
  cout << fixed << setprecision(10);
  cerr << fixed << setprecision(10);
  long long A;
  scanf("%lld", &A);
  long long B;
  scanf("%lld", &B);
  long long N;
  scanf("%lld", &N);
  int ans = 0;
  FOR(i, N - 10000000, N + 1) { ans = max(ans, (A * i) / B - A * (i / B)); }
  if (B >= 10000) {
    int i = B - 1;
    while (i <= N) {
      ans = max(ans, (A * i) / B - A * (i / B));
      i += B;
    }
  }
  cout << ans << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include "bits/stdc++.h"

using namespace std;

#define sp(x) cout << setprecision(x);
#define all(a) (a).begin(), (a).end()
#define inf 10000000
#define linf INT64_MAX * 0.99
#define int long long
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define yes "Yes"
#define no "No"
#define divs 1000000007
#define dive 1000000009
#define pi 3.141592653589793238

typedef pair<int, int> P;

signed main() {
  // ios::sync_with_stdio(false);
  // cin.tie(0);
  cout << fixed << setprecision(10);
  cerr << fixed << setprecision(10);
  long long A;
  scanf("%lld", &A);
  long long B;
  scanf("%lld", &B);
  long long N;
  scanf("%lld", &N);
  int ans = 0;
  REP(i, N + 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;
#define rep(i, N) for (int i = 0; i < (N); i++)
#define repo(i, N) for (int i = 1; i < (N); i++)
#define pb push_back
#define mp make_pair
#define ll long long
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
// #define num 1000000007
#define pi acos(-1.0)
// cout << fixed << setprecision (20);   小数点以下2０桁まで
// intの最大値2147483647 ≒ 2×10^9
// long longの最大値9223372036854775807 ≒ 9×10^18
// オーバーフローに注意 long long　にする
//'1'+=16;      で大文字Aに
//'大文字'+=32;  で小文字に
// string s = to_string(int数);
// int n = stoi(string文字列);

int main() {

  long long a, b, n;
  cin >> a >> b >> n;

  int ans;

  if (b - 1 <= n)
    ans = a * (b - 1) / b;

  else
    ans = (a * n) / b;

  cout << ans << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, N) for (int i = 0; i < (N); i++)
#define repo(i, N) for (int i = 1; i < (N); i++)
#define pb push_back
#define mp make_pair
#define ll long long
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
// #define num 1000000007
#define pi acos(-1.0)
// cout << fixed << setprecision (20);   小数点以下2０桁まで
// intの最大値2147483647 ≒ 2×10^9
// long longの最大値9223372036854775807 ≒ 9×10^18
// オーバーフローに注意 long long　にする
//'1'+=16;      で大文字Aに
//'大文字'+=32;  で小文字に
// string s = to_string(int数);
// int n = stoi(string文字列);

int main() {

  long long a, b, n;
  cin >> a >> b >> n;

  long long ans = -10000;
  repo(i, min(b + 1, n + 1)) {
    long long z = (a * i) / b - a * (i / b);
    ans = max(ans, z);
  }

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

#include <iostream>
using namespace std;

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

  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 <iostream>
using namespace std;

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

  int max = 0, res;

  for (int x = 1; x <= N; x++) {
    res = (A * x) / B - A * (x / B);
    if (max < res)
      max = res;
  }

  cout << max << 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++)
using ll = long long;
const ll MOD = 1000000007;

int main() {
  ll A, B, N, ans = 0;
  cin >> A >> B >> N;
  if (N >= B) {
    ans = A * (B - 1) / B;
  } else {
    ans = A * N / B;
  }
  cout << ans << 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++)
using ll = long long;
const ll MOD = 1000000007;

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


#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>

using namespace std;

int main() {

  long long int a, b, n;

  cin >> a >> b >> n;

  long long int x = min(b - 1, n);

  cout << a * x / b << endl;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>

using namespace std;

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

  long long int x = 0;
  int maxv = -1;
  int tmp = 0;

  while (x <= n) {
    tmp = (int)(a * x / b) - a * (int)(x / b);
    if (tmp > maxv) {
      maxv = tmp;
    }
    x++;
  }

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

#include <iostream>
using namespace std;

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

Error: 0

Fixed submission:

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

int main() {
  long long A, B, N;
  cin >> A >> B >> N;
  vector<int> ans(N + 1);
  for (int x = 1; x <= N; x++) {
    ans.at(x) = floor(A * x / B) - floor(x / B) * A;
  }
  sort(ans.begin(), ans.end());
  cout << ans.at(N) << endl;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

/*                    ॐ Shree ॐ                     */
/* ॐ ॐ ॐ
ॐ भूर् भुवः स्वः
तत् सवितुर्वरेण्यं
भर्गो देवस्य धीमहि
धियो यो नः प्रचोदयात्
*/
using namespace std;
typedef long long int ll;
vector<int> ve(3006, 0);
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#else
// online submission
#endif
  long long int a, b, c;
  cin >> a >> b >> c;
  ll mx = 0, ans = 0;
  ll x = min(b - 1, c);
  ll t = floor((double)(a * x / b)) - a * floor((double)(x / b));
  cout << t;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

/*                    ॐ Shree ॐ                     */
/* ॐ ॐ ॐ
ॐ भूर् भुवः स्वः
तत् सवितुर्वरेण्यं
भर्गो देवस्य धीमहि
धियो यो नः प्रचोदयात्
*/
using namespace std;
typedef long long int ll;
vector<int> ve(3006, 0);
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#else
// online submission
#endif
  long long int a, b, c;
  cin >> a >> b >> c;
  ll mx = 0, ans = 0;
  for (int x = b / a; x <= min(b, c); x++) {
    ll t = floor((double)(a * x / b)) - a * floor((double)(x / b));
    mx = max(t, mx);
  }
  cout << mx;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

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

using ll = long long;
using vi = vector<int>;
using vi2 = vector<vector<int>>;
#define MP(a, b) make_pair((a), (b))
#define MT(...) make_tuple(__VA_ARGS__)

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)

#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;

#define DCOUT(x, n) cout << fixed << setprecision(n) << (x) << endl;

#define sz(x) (int)(x).size()

template <typename T> inline istream &operator>>(istream &i, vector<T> &v) {
  REP(j, sz(v)) i >> v[j];
  return i;
}

int main() {
  ll A, B, N;
  cin >> A >> B >> N;
  ll x = min(B - 1, N);
  cout << (A * x) / B << 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 Max = 0;
  long long f = 0;

  for (long long x = 0; x <= N; x++) {
    f = A * x / B - A * (x / B);

    if (f > Max) {
      Max = f;
    }
  }

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

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <mutex>
#include <string>
#include <thread>
#include <vector>

using namespace std;

int main(void) {
  double a, b, n;

  cin >> a >> b >> n;

  double max;

  if (b - 1 > n) {
    max = floor((a * n) / b) - a * floor(n / b);
  } else {
    max = floor((a * (b - 1)) / b);
  }

  cout << max;
  return 0;
}

/*
        int n, m, q;
        int a[50], b[50], c[50], d[50];

        cin >> n >> m >> q;
        for (int i = 0; i < q; i++)
        {
                cin >> a[i] >> b[i] >> c[i] >> d[i];
        }

        int A[10];

        for (int i = 0; i < q; i++)
        {

        }
*/

Error: TLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <mutex>
#include <string>
#include <thread>
#include <vector>

using namespace std;

int main(void) {
  double a, b, n;

  cin >> a >> b >> n;

  double max = 0;

  for (int i = 1; i <= n && i <= b; i++) {
    double hoge;
    hoge = floor((a * i) / b) - a * floor(i / b);
    if (hoge > max) {
      max = hoge;
    }
  }

  cout << max;
  return 0;
}

/*
        int n, m, q;
        int a[50], b[50], c[50], d[50];

        cin >> n >> m >> q;
        for (int i = 0; i < q; i++)
        {
                cin >> a[i] >> b[i] >> c[i] >> d[i];
        }

        int A[10];

        for (int i = 0; i < q; i++)
        {

        }
*/
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cmath>
#include <cstring>
#include <fstream>
#include <iostream>
#include <string>
using namespace std;
int main() {
  unsigned long long a, b;
  long long max = -9999999;
  unsigned long long n;
  int h;
  cin >> a >> b >> n;
  for (int i = 0; i <= n / b; i++) {
    h = i;
  }
  if (h > 0) {
    for (int i = 0; i < 1; i++) {
      if (max < floor(a * ((b - 1) + i * b) / b) - a * i)
        max = floor(a * ((b - 1) + i * b) / b) - a * i;
    }
  }
  if (max < floor(a * n / b) - floor(n / b) * a)
    max = floor(a * n / b) - floor(n / b) * a;
  cout << max;
}


Error: TLE

Fixed submission:

#include <cmath>
#include <cstring>
#include <fstream>
#include <iostream>
#include <string>
using namespace std;
int main() {
  unsigned long long a, b;
  long long max = -9999999;
  unsigned long long n;
  int h;
  cin >> a >> b >> n;
  for (int i = 0; i <= n / b; i++) {
    h = i;
  }
  for (int i = 0; i < h; i++) {
    if (max < floor(a * ((b - 1) + i * b) / b) - a * i)
      max = floor(a * ((b - 1) + i * b) / b) - a * i;
  }
  if (max < floor(a * n / b) - floor(n / b) * a)
    max = floor(a * n / b) - floor(n / b) * a;
  cout << max;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

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


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  long long a, b, c;
  cin >> a >> b >> c;
  long long maxn = -999999;
  for (long long i = 0; i < c / 2; i++) {
    long long k = (a * i) / b - a * (i / b);
    maxn = max(maxn, k);
  }
  for (long long i = c / 2; i <= c; i++) {
    long long k = (a * i) / b - a * (i / b);
    maxn = max(maxn, k);
  }
  cout << maxn;
  return 0;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define REP(i, d, n) for (int i = (d); i < (n); ++i)
#define all(v) v.begin(), v.end()
using P = pair<int, int>;

int a, b, n;

int calc(int x) { return (int)(floor(a * x / b) - a * floor(x / b)); }

signed main() {

  cin >> a >> b >> n;

  cout << calc(min(b - 1, n)) << endl;

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define REP(i, d, n) for (int i = (d); i < (n); ++i)
#define all(v) v.begin(), v.end()
using P = pair<int, int>;

signed main() {

  int a, b, n;
  cin >> a >> b >> n;

  int ans = 0;
  for (int i = n, idx = 0; i > 0 && idx <= 1e6; --i, idx++) {
    ans = max(ans, (int)(floor(a * i / b) - a * floor(i / b)));
  }
  for (int i = 0; i <= n; i++) {
    ans = max(ans, (int)(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() {
  long long a, b, n;
  cin >> a >> b >> n;
  long long x = min(n, b - 1);
  cout << (a * x / b) - a * (x / b) << endl;
  return 0;
}


Error: TLE

Fixed submission:

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

int main() {
  long long a, b, n;
  cin >> a >> b >> n;
  long long ans = 0;
  long long d = 0;
  if (n >= b) {
    for (long long i = 0; i <= n; i++) {
      long long ans1 = (a * i / b) - a * (i / b);
      // cout << a * i / b << " " << a * (i / b) << " " << ans1 << endl;
      if (ans1 == 0) {
        if (d != 0) {
          ans = d;
          i = n + 100;
        }
      } else {
        d = ans1;
      }
    }
  } else {
    ans = (a * n / 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;
  long long ans, x;
  cin >> A >> B >> N;

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

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

int main() {
  long long A, B, N, t, m, tmp;
  m = 0;
  cin >> A >> B >> N;
  t = B;
  if (B > N)
    t = N;
  for (int x = B / A; x <= t; x++) {
    tmp = (A * x) / B - A * (x / B);
    if (tmp > m)
      m = tmp;
  }
  cout << m << endl;
}