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

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;

const ll INF = 1e18;
const ll MOD = 1000000007;
const ll MX = 0; // 最大値

ll dp[MX][MX];
inline void chmax(ll &a, ll b) { a = max(a, b); }

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((ll)(x).size()) // sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define PB push_back

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

  if (n >= b) {
    ll c = (n / b + 1) * b - 1;
    if (c - 1 > n)
      c = c - b;
    n = c;
  }

  ll x = a * n / b;
  ll y = n / b;
  cout << x - a * y << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;

const ll INF = 1e18;
const ll MOD = 1000000007;
const ll MX = 0; // 最大値

ll dp[MX][MX];
inline void chmax(ll &a, ll b) { a = max(a, b); }

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((ll)(x).size()) // sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define PB push_back

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

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

#include <bits/stdc++.h>
int main() {
  using namespace std;
  long A, B, N, x;
  cin >> A >> B >> N;
  x = (N >= B) ? B - 1 : N;
  cout << A * x / B - A * (x / B) << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
int main() {
  using namespace std;
  long A, B, N, max(0), tmp(0);
  cin >> A >> B >> N;
  for (int x = 1; x <= N; x++) {
    tmp = (A * x) / B - A * (x / B);
    max = tmp > max ? tmp : max;
  }
  cout << max << endl;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
int main() {
  long long a, b, n, ans;
  cin >> a >> b >> n;
  ans = a * (b - 1) / b - a * ((b - 1) / b);
  if (n < b) {
    ans = a * n / b - a * (n / b);
  }
  cout << ans << endl;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
using namespace std;
int main() {
  long long a, b, n, ans = 0;
  cin >> a >> b >> n;
  for (long long i = 0; i <= n; i++) {
    long long f = a * i / b - a * (i / b);
    ans = max(f, ans);
  }
  cout << ans << endl;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for (int i = a; i < b; i++)
#define each(i, mp) for (auto &i : mp)

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

  ll ans = 0;
  ll tmp = 0;
  // rep(x,n+1)
  bool is_stop = 0;
  // for (ll x = 0; x < n+1; x++){
  //   tmp = floor(a*(long double)x/b) - a*floor((long double)x/b);
  //   if (tmp >= ans) ans = tmp;
  //   if(x%(ll)b == 0){
  //     if (is_stop) break;
  //     is_stop = 1;
  //   }
  //   // cout << x<< " " << tmp<< " " << a*(long double)x/b<<endl;
  // }
  if (n >= b) {
    ans = floor(a * (b - 1.0) / b) - a * floor((b - 1.0) / b);
  } else {
    ans = floor(a * n / b) - a * floor(n / b);
  }
  cout << ans << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for (int i = a; i < b; i++)
#define each(i, mp) for (auto &i : mp)

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

  ll ans = 0;
  ll tmp = 0;
  // rep(x,n+1)
  bool is_stop = 0;
  for (ll x = 0; x < n + 1; x++) {
    tmp = floor(a * (long double)x / b) - a * floor((long double)x / b);
    if (tmp >= ans)
      ans = tmp;
    if (x % (ll)b == 0) {
      if (is_stop)
        break;
      is_stop = 1;
    }
    // cout << x<< " " << tmp<< " " << a*(long double)x/b<<endl;
  }
  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 = 0;
  cin >> a >> b >> n;
  if (n < b) {
    m = (a * n) / b;
  } else {
    m = (a * (b - 1)) / b;
  }
  cout << m << endl;
}

Error: TLE

Fixed submission:

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

#include <iostream>
#include <list>
#include <queue>
#include <vector>

using namespace std;

#define MIN(x, y) x < y ? x : y
#define MAX(x, y) x < y ? y : x
#define ABS(x, y) x < y ? (y - x) : (x - y)

typedef long long Long;

int main() {
  Long a, b, n;
  Long p, q;
  Long ans = 0;

  cin >> a >> b >> n;

  Long x = 0;

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

  p = (a * x) / b;
  q = x / b;
  q = q * a;
  ans = p - q;

  /*
          for(x=0; x<=n ; x++) {
                  p = (a*x)/b;
                  q = x/b;
                  q = q*a;
                  ans = MAX(ans, p-q);

                  cout<<p<<" "<<q<<endl;
          }
  */
  cout << ans << endl;

  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
#include <list>
#include <queue>
#include <vector>

using namespace std;

#define MIN(x, y) x < y ? x : y
#define MAX(x, y) x < y ? y : x
#define ABS(x, y) x < y ? (y - x) : (x - y)

typedef long long Long;

int main() {
  Long a, b, n;
  Long p, q;
  Long ans = 0;

  cin >> a >> b >> n;

  Long x = 0;

  for (x = 0; x <= n; x++) {
    p = (a * x) / b;
    q = x / b;
    q = q * a;
    ans = MAX(ans, p - q);
  }

  cout << ans << endl;

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

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll MOD = 1000000007;
constexpr ll INF = 1ll << 60;

ll A, B, N;

inline ll f(ll n) { return ((A * n) / B) - A * (n / B); }

int main(int argc, char **argv) {
  cin >> A >> B >> N;
  std::cout << f(min(N, B - 1)) << std::endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll MOD = 1000000007;
constexpr ll INF = 1ll << 60;

ll A, B, N;

inline ll f(ll n) { return ((A * n) / B) - A * (n / B); }

int main(int argc, char **argv) {
  cin >> A >> B >> N;
  ll res{0};
  for (ll i = N / 2; i <= N; ++i) {
    res = max(res, f(i));
  }
  std::cout << res << std::endl;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

/*
 * author :Sadik Hassan
 *
 */
#include "bits/stdc++.h"
using namespace std;
#define ll long long
#define nl "\\n"
#define pb push_back
#define fi first
#define se second
#define PI (acos(-1.0))
#define _SAD() ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define repp(i, a, n) for (int i = a; i < n; i++)
#define rep(i, n) for (int i = 0; i < n; i++)
#define SZ(s) s.size()
#define SRT(x, y) sort(x, x + y)
#define REV(a, b) reverse(a, a + b)
#define VSRT(x) sort(x.begin(), x.end())
#define VREV(x) reverse(x.begin(), x.end())
#define w(t)                                                                   \\
  int t;                                                                       \\
  cin >> t;                                                                    \\
  while (t--)
#define TSFL(s) transform(s.begin(), s.end(), s.begin(), ::toupper);
#define TSFH(s) transform(s.begin(), s.end(), s.begin(), ::tolower);
typedef vector<int> vi;
typedef vector<ll> vii;
typedef set<int> si;
typedef set<ll> sii;

const int N = 1e5 + 10;
const ll xy = 1e11 + 10000000;
const int INF = (int)1e9 + 5;

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


Error: TLE

Fixed submission:

/*
 * author :Sadik Hassan
 *
 */
#include "bits/stdc++.h"
using namespace std;
#define ll long long
#define nl "\\n"
#define pb push_back
#define fi first
#define se second
#define PI (acos(-1.0))
#define _SAD() ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define repp(i, a, n) for (int i = a; i < n; i++)
#define rep(i, n) for (int i = 0; i < n; i++)
#define SZ(s) s.size()
#define SRT(x, y) sort(x, x + y)
#define REV(a, b) reverse(a, a + b)
#define VSRT(x) sort(x.begin(), x.end())
#define VREV(x) reverse(x.begin(), x.end())
#define w(t)                                                                   \\
  int t;                                                                       \\
  cin >> t;                                                                    \\
  while (t--)
#define TSFL(s) transform(s.begin(), s.end(), s.begin(), ::toupper);
#define TSFH(s) transform(s.begin(), s.end(), s.begin(), ::tolower);
typedef vector<int> vi;
typedef vector<ll> vii;
typedef set<int> si;
typedef set<ll> sii;

const int N = 1e5 + 10;
const ll xy = 1e11 + 10000000;
const int INF = (int)1e9 + 5;

int main() {
  _SAD()
  ll a, b, n;
  cin >> a >> b >> n;
  ll ans = 1e-18, cnt = 0;
  if (n > xy) {
    ll sap = sqrt(n);
    for (ll i = n - (sap + 999999999); i <= n; i++) {
      cnt = ((a * i) / b) - (a * (i / b));
      if (cnt < ans)
        break;
      ans = max(cnt, ans);
    }
    cout << ans << nl;
    return 0;
  }
  for (ll i = n / 2; i <= min(n, xy); i++) {
    cnt = ((a * i) / b) - (a * (i / b));
    ans = max(cnt, ans);
  }
  cout << ans << nl;
  return 0;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

//
//	Created by shamim_nik
//

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef tree<int, null_type, less<int>, rb_tree_tag,
             tree_order_statistics_node_update>
    indexed_set;

#define br printf("\\n")

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

  //	freopen("input.txt", "r", stdin);
  //	freopen("output.txt", "w", stdout);

  long long a, b, n, x;
  cin >> a >> b >> n;
  x = min(b - 1, n);
  cout << (floor((a * x) / b) - a * floor(x / b)) << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define set0(a) memset((a), 0, sizeof(a))
#define set1(a) memset((a), -1, sizeof(a))
#define pi pair<int, int>
#define ps pair<string, string>
#define pl pair<long, long>
#define pll pair<long long, long long>
#define vll vector<long long>
#define vl vector<long>
#define vi vector<int>
#define vs vector<string>
#define vps vector<ps>
#define vpi vector<pi>
#define vpl vector<pl>
#define vpll vector<pll>
#define flash                                                                  \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);
#define tc(t, T) for (long long t = 0; t < T; t++)
#define rep(i, s, n, d) for (long long i = s; i < n; i = i + d)

bool sortbysec(const pll &a, const pll &b) { return (a.second < b.second); }
/*bool cxp pair<ll, pll> &a,
              const pair<ll, pll> &b)
{
    return (a.ff < b.ff);
}*/

void func(void) {
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
}
ll gcd(ll a, ll b) {
  if (b == 0)
    return a;
  else
    gcd(b, a % b);
}
void printStack(stack<string> s) {
  if (s.empty())
    return;

  string x = s.top();
  s.pop();
  printStack(s);
  cout << x;
  s.push(x);
}

int main() {

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

  ll left = 1;
  ll right = min(b, n);
  ll mid = 1;
  ll min1 = 0;
  ll max1 = 0;
  ll x = 1;

  while (right - left >= 5) {
    mid = (right + left) / 2;
    ll d = (a * mid) / b - a * (mid / b);
    // cout<<d<<endl;

    if (d >= max1) {
      max1 = d;
      x = mid;
      left = mid;
    } else
      right = mid;
  }
  for (int i = left; i <= right; i++) {
    ll d = (a * i) / b - a * (i / b);
    if (d > max1) {
      max1 = d;
      x = i;
    }
  }
  cout << max1 << endl;
}

// 1 2 3 1 5 3 1 0 1 0 2
// 1 2 3 4 5 6 7 8 9 10 11
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define AlisherAnush KamilaLaylo

using namespace std;

long long a, b, c, q, d;

int main() {
  cin >> a >> b >> c;
  q = min(b - 1, c);
  cout << ((a * q / b) - a * (q / b));
}


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 = INT_MIN;
  for (int x = 0; x <= n; x++) {
    long long int y = a * x / b - a * (x / b);
    ans = max(ans, y);
  }
  cout << ans;
  return 0;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

// #include<bits/stdc++.h>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>

typedef long long ll;
typedef double db;
typedef unsigned long long ull;
const double pi = 2 * acos(0);

#define pf printf
#define sf scanf
#define pb(a) push_back(a)
#define for0(i, n) for (int i = 0; i < n; i++)
#define for1(i, n) for (int i = 1; i <= n; i++)
#define forab(a, b) for (int i = a; i <= b; i++)
// #define gcd(a, b)     __gcd(a, b)
#define lcm(a, b) ((a) * ((b) / gcd(a, b)))
#define sq(a) (a) * (a)
#define nw "\\n"
#define abs(x) fabs(x)
#define pcase(z, x) cout << "Case " << z << ": " << x << "\\n"
#define CIN                                                                    \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0)

using namespace std;

int main() {
  ll a, b, n, x, mx;
  cin >> a >> b >> n;
  if (n >= b)
    x = b - 1;
  else
    x = n;

  mx = ((a * x) / b);
  mx -= a * (x / b);

  cout << mx << nw;
  return 0;
}

Error: TLE

Fixed submission:

// #include<bits/stdc++.h>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>

typedef long long ll;
typedef double db;
typedef unsigned long long ull;
const double pi = 2 * acos(0);

#define pf printf
#define sf scanf
#define pb(a) push_back(a)
#define for0(i, n) for (int i = 0; i < n; i++)
#define for1(i, n) for (int i = 1; i <= n; i++)
#define forab(a, b) for (int i = a; i <= b; i++)
// #define gcd(a, b)     __gcd(a, b)
#define lcm(a, b) ((a) * ((b) / gcd(a, b)))
#define sq(a) (a) * (a)
#define nw "\\n"
#define abs(x) fabs(x)
#define pcase(z, x) cout << "Case " << z << ": " << x << "\\n"
#define CIN                                                                    \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0)

using namespace std;

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

#include <climits>
#include <cmath>
#include <iostream>
#define ll long long
using namespace std;
int main() {
  ll a, b, c, k1, k2;
  cin >> a >> b >> c;
  if (c >= b)
    c = b - 1;
  cout << floor((a * c) / b) - (a * floor(c / b));
  return 0;
}

Error: TLE

Fixed submission:

#include <climits>
#include <cmath>
#include <iostream>
#define ll long long
using namespace std;
int main() {
  ll a, b, c, k = INT_MIN, temp;
  cin >> a >> b >> c;
  for (ll i = 1; i <= c; i++) {
    temp = floor((a * i) / b) - (a * floor(i / b));
    k = max(k, temp);
  }
  cout << k;
  return 0;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const double eps = 1e-8;
const int NINF = 0xc0c0c0c0;
const int INF = 0x3f3f3f3f;
const ll mod = 1e9 + 7;
const ll maxn = 1e6 + 5;

ll a, b, n;

ll check(ll x) { return (a * x) / b - a * (x / b); }

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> a >> b >> n;
  ll L = 1, R = n;
  while (R > L) {
    ll m1 = L + (R - L) / 3;
    ll m2 = R - (R - L) / 3;
    if (check(m1) > check(m2))
      R = m2 - 1;
    else
      L = m1 + 1;
  }
  cout << check(L) << '\\n';
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const double eps = 1e-8;
const int NINF = 0xc0c0c0c0;
const int INF = 0x3f3f3f3f;
const ll mod = 1e9 + 7;
const ll maxn = 1e6 + 5;

ll a, b, n;

double check(ll x) { return floor(1.0 * a * x / b) - a * floor(1.0 * x / b); }

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> a >> b >> n;
  ll L = 0, R = n + 1, mid, mmid;
  while (R - L > 10) {
    mid = (R - L) / 3 + L;
    mmid = R - (R - L) / 3;
    if (check(mid) > check(mmid)) {
      R = mmid;
    } else {
      L = mid;
    }
    // cout<<"L="<<L<<" R="<<R<<" mid="<<mid<<" mmid="<<mmid<<'\\n';
  }
  // cout<<"R="<<R<<" L="<<L<<"\\n";
  ll mx = 0;
  for (int i = L; i <= min(R, n); i++) {
    // cout<<"i="<<i<<" check(i)="<<check(i)<<'\\n';
    if (check(i) > mx) {
      mx = check(i);
    }
  }
  cout << mx << '\\n';
  return 0;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

/*
  GOOD is not Enough
  You've got to be GREAT.
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
// #include<boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
using namespace __gnu_pbds;
using namespace std;
#define int long long
#define mod 1000000007
#define FAST ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define f(i, n) for (int i = 0; i < n; i++)
#define fp(i, k, n) for (int i = k; i <= n; i++)
#define fr(i, k, n) for (int i = k; i >= n; i--)
#define pb push_back
#define pii pair<int, int>
#define dbg(x) cout << (#x) << " is " << (x) << '\\n'
#define F first
#define S second
#define all(a) a.begin(), a.end()
typedef tree<int, null_type, less_equal<int>, rb_tree_tag,
             tree_order_statistics_node_update>
    ordered_set;

void solve() {
  int a, b, n;
  cin >> a >> b >> n;
  int ans = 0;
  int x = 0;
  x = min(n, b - 1);
  cout << (a * x) / b << '\\n';
  return;
}

signed main() {
  FAST int T = 1;
  // cin >> T;
  while (T--) {
    solve();
  }
  return 0;
}

Error: TLE

Fixed submission:

/*
  GOOD is not Enough
  You've got to be GREAT.
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
// #include<boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
using namespace __gnu_pbds;
using namespace std;
#define int long long
#define mod 1000000007
#define FAST ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define f(i, n) for (int i = 0; i < n; i++)
#define fp(i, k, n) for (int i = k; i <= n; i++)
#define fr(i, k, n) for (int i = k; i >= n; i--)
#define pb push_back
#define pii pair<int, int>
#define dbg(x) cout << (#x) << " is " << (x) << '\\n'
#define F first
#define S second
#define all(a) a.begin(), a.end()
typedef tree<int, null_type, less_equal<int>, rb_tree_tag,
             tree_order_statistics_node_update>
    ordered_set;

void solve() {
  int a, b, n;
  cin >> a >> b >> n;
  int ans = 0;
  int x = 0;
  fr(i, n, 0) {
    int res = ((a * i) / b) - (a * (i / b));
    ans = max(res, ans);
    x++;
    if (x == 100000000)
      break;
  }
  x = 0;
  fp(i, 0, n) {
    int res = ((a * i) / b) - (a * (i / b));
    ans = max(res, ans);
    x++;
    if (x == 100000000)
      break;
  }
  cout << ans << '\\n';
  return;
}

signed main() {
  FAST int T = 1;
  // cin >> T;
  while (T--) {
    solve();
  }
  return 0;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
const ll INF = 1LL << 60;

// floor(a/b)=(a-a%b)/bとすることでfloorを消せる

int main() {
  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;
}

Error: TLE

Fixed submission:


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
const ll INF = 1LL << 60;

int main() {
  long double a, b, n;
  cin >> a >> b >> n;
  long double ans = 0;
  for (int i = n - n / 10; i <= n; i++) {
    long double f;
    f = floor((a * i) / b) - a * floor(i / b);
    ans = max(ans, f);
  }

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

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

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

  if (N > B - 1)
    N = B - 1;
  cout << floor(A * N / B) - A * (N / B) << endl;
  return 0;
}

Error: TLE

Fixed submission:

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

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

  long long int output, num;
  output = 0;

  if (N > B) {
    N = B;
  }

  for (int i = 1; i <= N; i++) {
    num = floor((A * i) / B) - A * floor(i / B);
    if (num >= output) {
      output = num;
    }
  }
  cout << output << endl;
  return 0;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
using namespace std;
typedef long long ll;

void Main() {
  ll a, b, n;
  cin >> a >> b >> n;
  int max = 0;

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

int main() {
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  std::cout << std::fixed << std::setprecision(15);
  Main();
}

Error: TLE

Fixed submission:

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
using namespace std;
typedef long long ll;

void Main() {
  ll a, b, n;
  cin >> a >> b >> n;
  int max = -1;
  ll t = 0;
  for (ll x = 1; x <= n; ++x) {
    t = floor(a * x / b) - a * floor(x / b);
    if (t > max) {
      max = t;
    }
  }
  cout << max << endl;
}

int main() {
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  std::cout << std::fixed << std::setprecision(15);
  Main();
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
using namespace std;
int main() {
  long long a, b, n, x;
  cin >> a >> b >> n;
  x = min(n, b - 1);
  cout << a * (x % b) / b << endl;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
using namespace std;
int main() {
  long long a, b, n, Max = 0;
  cin >> a >> b >> n;
  for (int x = 1; x <= n; x++) {
    Max = max(Max, a * x / b - a * (x / b));
  }
  cout << Max << endl;
}