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

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

#define GO                                                                     \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define int long long int

const int maxr = 1e5 + 5;

int32_t main() {
  GO;
  int a, b, n;
  cin >> a >> b >> n;
  int ans = 0;
  int val = (b / n) * n;
  int i = val - 1;
  if (i >= 0 && i <= n)
    ans = max(ans, (a * i) / b - a * (i / b));
  i = (n / b) * b;
  i--;
  if (i >= 0 && i <= n)
    ans = max(ans, (a * i) / b - a * (i / b));
  i = n;
  ans = max(ans, (a * i) / b - a * (i / b));
  cout << ans << endl;
  return 0;
}

//!

Error: TLE

Fixed submission:

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

#define GO                                                                     \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define int long long int

const int maxr = 1e5 + 5;

int32_t main() {
  GO;
  int a, b, n;
  cin >> a >> b >> n;
  int ans = 0;
  for (int i = 0; i <= n; i++) {
    int value = (a * i) / b - a * (i / b);
    ans = max(ans, value);
  }
  cout << ans << endl;
  return 0;
}

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

// Floor Function

/*
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) a / __gcd(a, b) * b
#define range(a) (a).begin(),(a).end()
const int inf = 2147483647;

int main (){
    ll a,b,n,ans=0;cin>>a>>b>>n;
    rep(i,1,n+1){
        cout << i << " " << (i*a)/b-a*(i/b) << endl;
        ans =max((i*a)/b-a*(i/b),ans);
    }

    cout << ans << endl;
    return 0;
}
*/
// Floor Function

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, x, y) for (int i = x; i < y; i++)
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) a / __gcd(a, b) * b
#define range(a) (a).begin(), (a).end()
const int inf = 2147483647;

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

Error: TLE

Fixed submission:

//

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, x, y) for (int i = x; i < y; i++)
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) a / __gcd(a, b) * b
#define range(a) (a).begin(), (a).end()
const int inf = 2147483647;

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

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll a, b, n;
  cin >> a >> b >> n;
  ll max = 0;
  ll ans = 0;
  ll lol = 0;
  ll x = min(b - 1, n);
  max = (a * x) / b - a * (x / b);
  cout << max << endl;
  return 0;
}

Error: TLE

Fixed submission:

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

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

// #pragma GCC optimize("Ofast")

#pragma GCC optimize("O3")
// #pragma GCC target("avx,avx2,fma")
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
constexpr auto INF = 9223372036854775807;
typedef long long int ll;
typedef unsigned long long int ull;
typedef unsigned long int ul;
#define f(i, a, b) for (ll i = (ll)a; i < (ll)b; i += 1)
#define rf(i, a, b) for (ll i = (ll)a; i >= (ll)b; i -= 1)
#define endl '\\n'
#define N 1000000007 // prime modulo value
#define C 1000000001
#define M 998244353
#define all(x) x.begin(), x.end()
using namespace std;
// From Geeksforgeeks
inline ll gcd(ll a, ll b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
// Power function took from geeksforgeeks
ll power(ll x, ll y) {
  ll res = 1;

  x = x;
  if (x == 0)
    return 0;
  while (y > 0) {
    if (y & 1)
      res = (res * x);
    y = y >> 1;
    x = (x * x);
  }
  return res;
}
double dist(ll x1, ll y1, ll x2, ll y2) {
  double ans = sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
  return ans;
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  ll a, b, n;
  cin >> a >> b >> n;
  ll ans = (a * min(n, b - 1)) / b;
  cout << ans;
  return 0;
}

Error: TLE

Fixed submission:

// #pragma GCC optimize("Ofast")

#pragma GCC optimize("O3")
// #pragma GCC target("avx,avx2,fma")
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
constexpr auto INF = 9223372036854775807;
typedef long long int ll;
typedef unsigned long long int ull;
typedef unsigned long int ul;
#define f(i, a, b) for (ll i = (ll)a; i < (ll)b; i += 1)
#define rf(i, a, b) for (ll i = (ll)a; i >= (ll)b; i -= 1)
#define endl '\\n'
#define N 1000000007 // prime modulo value
#define C 1000000001
#define M 998244353
#define all(x) x.begin(), x.end()
using namespace std;
// From Geeksforgeeks
inline ll gcd(ll a, ll b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
// Power function took from geeksforgeeks
ll power(ll x, ll y) {
  ll res = 1;

  x = x;
  if (x == 0)
    return 0;
  while (y > 0) {
    if (y & 1)
      res = (res * x);
    y = y >> 1;
    x = (x * x);
  }
  return res;
}
double dist(ll x1, ll y1, ll x2, ll y2) {
  double ans = sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
  return ans;
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  ll a, b, n;
  cin >> a >> b >> n;
  ll maxi = 0;
  f(i, 0, n + 1) {
    ll ta = floor((a * i) / b);
    ll tb = floor(i / b);
    maxi = max(maxi, ta - (a * tb));
  }
  cout << maxi;
  return 0;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
int main() {
  long long A, B, N;
  cin >> A >> B >> N;
  long long ans = 0;
  long long NN = min(B - 1, N);
  long long C = A * NN;
  long long D = C / B;
  long long E = NN / B;
  ans = D - A * E;
  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 < (int)(n); i++)
#define all(v) v.begin(), v.end()
int main() {
  long long A, B, N;
  cin >> A >> B >> N;
  long long ans = 0;
  long long NN = min(B, N);
  for (int i = 0; i <= NN; i++) {
    long long C = A * i;
    long long D = C / B;
    long long E = i / B;
    ans = max(ans, D - A * E);
  }
  cout << ans << endl;
  return 0;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int main() {
  long long a, b, n;
  int ans;
  cin >> a >> b >> n;
  long long x = min(b - 1, n);
  ans = (a * x) / b - a * (x / b);
  cout << ans << endl;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

int main(void) {
  long long A, B, N, s, e;
  int ans = 0, ans1 = 0, ans2 = 0, ans3 = 0;
  int x1, x2, x3;
  cin >> A >> B >> N;
  s = 0ll;
  e = N;
  while (s < e - 1) {
    if (s == e) {
      x1 = s;
      ans = int(x1 * A / B) - A * int(x1 / B);
      break;
    }
    x1 = s;
    ans1 = int(x1 * A / B) - A * int(x1 / B);
    x2 = s + (e - s) / 2;
    ans2 = int(x2 * A / B) - A * int(x2 / B);
    x3 = e;
    ans3 = int(x3 * A / B) - A * int(x3 / B);
    if (ans1 > ans2) {
      e = x2;
      ans = ans1;
    } else if (ans3 > ans2) {
      s = x2;
      ans = ans3;
    } else {
      s = s + 1;
      ans = ans2;
    }
    // cout << "s=" << s << " e=" << e << endl;
  }
  cout << ans << endl;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

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

#define ll long long

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

  ll max = 0;
  if (B > N) {
    max = (A * N / B) / 1 - A * ((N / B) / 1);
  } else {
    max = (A * (B - 1) / B) / 1 - A * (((B - 1) / B) / 1);
  }
  cout << max << endl;
}

Error: TLE

Fixed submission:

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

#define ll long long

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

  ll max = 0;
  for (ll x = 0; x <= N; x++) {
    if (max < (A * x / B) / 1 - A * ((x / B) / 1)) {
      max = (A * x / B) / 1 - A * ((x / B) / 1);
    }
  }
  cout << max << endl;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define space " "
#define MOD (long long)1000000007
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename T> void __f(const char *variable_name, T &&value) {
  cout << variable_name << ": " << value << endl;
}
template <typename T1, typename... T2>
void __f(const char *names, T1 &&arg1, T2 &&...args) {
  const char *comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

const ll N = 5e5 + 5;
ll *v;
ll a, b, n;

void solve() {
  cin >> a >> b >> n;
  ll _max = 0, val, x;
  if (b > n)
    x = n;
  else if (b == n)
    x = n - 1;
  else
    x = b - 1;
  double t1 = (a * x) / b, t2 = x / b;
  val = floor(t1) - (a * floor(t2));
  // trace(x, val);
  _max = max(_max, val);
  cout << _max;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ll t = 1;
  // cout << "\\n\\nBLAH BLAH BLAH\\n\\n";
  // cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define space " "
#define MOD (long long)1000000007
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename T> void __f(const char *variable_name, T &&value) {
  cout << variable_name << ": " << value << endl;
}
template <typename T1, typename... T2>
void __f(const char *names, T1 &&arg1, T2 &&...args) {
  const char *comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

const ll N = 5e5 + 5;
ll *v;
ll a, b, n;

void solve() {
  cin >> a >> b >> n;
  ll mult = 1;
  ll _max = 0, val, x = min(n, mult * b - 1);
  while (x <= n) {
    double t1 = (a * x) / b, t2 = x / b;
    val = floor(t1) - (a * floor(t2));
    // trace(x, val);
    _max = max(_max, val);
    mult++;
    x = mult * b - 1;
  }
  cout << _max;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ll t = 1;
  // cout << "\\n\\nBLAH BLAH BLAH\\n\\n";
  // cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

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

#define all(v) v.begin(), v.end()
typedef long long ll;

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

  ll x = n;
  if (b <= n)
    x = b - 1 ? b - 1 : 1;
  ll res = floor(a * x / b) - a * floor(x / b);
  cout << res << endl;
}


Error: TLE

Fixed submission:

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

#define all(v) v.begin(), v.end()
typedef long long ll;

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

  ll res = 0;
  for (int i = 0; i <= n; i++) {
    ll tmp = floor(a * i / b) - a * floor(i / b);
    res = max(res, tmp);
  }
  cout << res << endl;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <vector>
#define ULL unsigned long long
using namespace std;

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

  ULL x = min(N, B - 1);
  ULL ret = A * x / B - A * (x / B);

  cout << ret << endl;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <vector>
#define ULL unsigned long long

ULL floor(double t) { return static_cast<ULL>(t); }

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

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

  ULL ret = 0;
  for (ULL x = 0; x <= N; x++) {
    chmax(ret, floor(A * x / B) - A * floor(x / B));
  }

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

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

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

  cout << a * (b - 1) / b << endl;
  return 0;
}

Error: TLE

Fixed submission:

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

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

  long long y = n / b;
  priority_queue<long long> pq;
  for (int i = 1; i < y + 1; i++) {
    pq.push(b * i - 1);
  }
  pq.push(n);
  long long max = 0;
  while (!pq.empty()) {
    long long mae = a * pq.top() / b;
    long long ushi = pq.top() / b;
    if (max < mae - ushi * a)
      max = mae - ushi * a;
    pq.pop();
  }

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

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

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

  ll maxX = std::min<ll>(B - 1, N);

  std::cout << A * (maxX) / B;

  return 0;
}


Error: WA

Fixed submission:

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

int main() {
  ll A, B, N;
  std::cin >> A, B, N;
  ll maxX = std::min(B - 1, N);

  std::cout << A * (maxX) / B;

  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 < n; i++)

int main() {
  ll a, b, n;
  cin >> a >> b >> n;
  ll test = min(b - 1, n);
  cout << floorl(a * test / b) << 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 < n; i++)

int main() {
  ll a, b, n;
  long double ans, test;
  cin >> a >> b >> n;
  for (ll x = 0; x <= n; x++) {
    test = floorl(a * x / b) - a * floorl(x / b);
    if (x == 0)
      ans = test;
    if (ans < test)
      ans = test;
  }
  cout << ans << "\\n";
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define endl "\\n"
using namespace std;
typedef long long int lli;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  lli a, b, n;
  cin >> a >> b >> n;
  lli x = min(b - 1, n);
  lli i, cur;

  if (n > b - 1) {
    cur = n - (b - 1);
    cur /= b;
    x = (b - 1) + cur * b;
  }
  // for(i=b-1;i<=n;i+=b)
  // {
  //     x=i;
  // }
  if (x == 0)
    x = 1;
  lli ans1 = (a * x) / b;
  lli ans2 = a * (x / b);
  cout << ans1 - ans2;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define endl "\\n"
using namespace std;
typedef long long int lli;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  lli a, b, n;
  cin >> a >> b >> n;
  lli x = min(b - 1, n);
  lli i;

  for (i = b - 1; i <= n; i += b) {
    x = i;
  }
  if (x == 0)
    x = 1;
  lli ans1 = (a * x) / b;
  lli ans2 = a * (x / b);
  cout << ans1 - ans2;
  return 0;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cstdint>
#include <iostream>
#include <math.h>
#include <sstream>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;
typedef long long ll;

ll ans, mx, mn, flag, sum, cnt;

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


Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdint>
#include <iostream>
#include <math.h>
#include <sstream>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;
typedef long long ll;

ll ans, mx, mn, flag, sum, cnt;

int main() {
  ll a, b, n;
  cin >> a >> b >> n;
  for (ll i = 1; i <= n; i++) {

    flag = floor(a * i / b) - a * floor(i / b);
    if (flag >= mx)
      mx = flag;
    else
      break;
  }
  cout << mx << endl;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = 0; i <= (n); i++)
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
const ll INF = 1LL << 60;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
using Graph = vector<vector<int>>;

typedef pair<int, int> P;

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 - A * (x / B);
  cout << ans << endl;
}

Error: TLE

Fixed submission:

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

const ll INF = 1LL << 60;

ll A, B, N;
ll max_v = -1;

ll calc(ll x) {

  return floor(A * x / (long double)B) - A * (floor(x / (long double)B));
}

bool isOK(ll index) {
  if (calc(index) > max_v) {
    max_v = calc(index);
    return true;
  } else {
    return false;
  }
}

// 汎用的な二分探索のテンプレ
int binary_search(ll ok, ll ng) {

  while (abs(ok - ng) > 1) {
    ll mid = (ok + ng) / 2;

    if (isOK(mid))
      ok = mid;
    else
      ng = mid;
  }
  return ok;
}

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

  // binary_search();

  // ll ans1, ans2;

  // cout << calc(1LL) << endl;
  // cout << calc(N) << endl;
  /*
      ll ok, ng;
      if (calc(1LL) < calc(N)){
          ok = N+1;
          ng = 0;
          //max_v = calc(1LL);
      }else{
          ok = 0;
          ng = N+1;
          //max_v = calc(N);
      }
  */
  ll ans = 0;
  rep(i, 16000000) {
    if (1 + i <= N) {
      ans = max(ans, calc(1 + i));
    }

    if (N / 2 - i > 0) {
      ans = max(ans, calc(N / 2 - i));
    }
    if (N / 2 + i <= N) {
      ans = max(ans, calc(N / 2 + i));
    }

    if (N / 4 - i > 0) {
      ans = max(ans, calc(N / 4 - i));
    }
    if (N / 4 + i <= N) {
      ans = max(ans, calc(N / 4 + i));
    }

    if (3 * N / 4 - i > 0) {
      ans = max(ans, calc(3 * N / 4 - i));
    }
    if (3 * N / 4 + i <= N) {
      ans = max(ans, calc(3 * N / 4 + i));
    }

    if (N / 4 - i > 0) {
      ans = max(ans, calc(N / 4 - i));
    }
    if (N / 4 + i <= N) {
      ans = max(ans, calc(N / 4 + i));
    }

    if (N / 5 - i > 0) {
      ans = max(ans, calc(N / 5 - i));
    }
    if (N / 5 + i <= N) {
      ans = max(ans, calc(N / 5 + i));
    }

    if (4 * N / 5 - i > 0) {
      ans = max(ans, calc(4 * N / 5 - i));
    }
    if (4 * N / 5 + i <= N) {
      ans = max(ans, calc(4 * N / 5 + i));
    }

    if (N - i > 0) {
      ans = max(ans, calc(N - i));
    }
  }

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

#include <cmath>
#include <iostream>
typedef long long ll;
using namespace std;

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

  ll x = min(n, b - 1);
  ll ans = a * x / b;

  cout << ans << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rep2(i, s, n) for (ll i = 1; i < (n); i++)
using namespace std;
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

int main() {
  ll a, b, n;
  cin >> a >> b >> n;
  ll ans = 0;
  ll temp;
  rep2(x, 1, n + 1) {
    temp = (a * x) / b - a * (ll)(x / b);
    if (temp > ans)
      ans = temp;
  }

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

#include <algorithm>
#include <bitset>
#include <chrono>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <stack>
#include <unordered_map>
#include <vector>
using namespace std;
using ll = long long;
const ll INF = (ll)1e18 + 1;
const ll DIV = 1000000007;
// #define TEST
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
#ifdef TEST
  chrono::system_clock::time_point start, end;
  start = chrono::system_clock::now();
#endif
  ll A, B, N;
  cin >> A >> B >> N;
  ll max_num = 0;
  ll x = min(B - 1, N);
  ll ax_b = (A * x) / B;
  ll x_b = x / B;
  cout << ax_b - A * x_b << endl;
#ifdef TEST
  end = chrono::system_clock::now();
  cerr << static_cast<double>(
              chrono::duration_cast<chrono::microseconds>(end - start).count() /
              1000.0)
       << "[ms]" << endl;
#endif
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <chrono>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <stack>
#include <unordered_map>
#include <vector>
using namespace std;
using ll = long long;
const ll INF = (ll)1e18 + 1;
const ll DIV = 1000000007;
// #define TEST
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
#ifdef TEST
  chrono::system_clock::time_point start, end;
  start = chrono::system_clock::now();
#endif
  ll A, B, N;
  cin >> A >> B >> N;
  ll max_num = 0;
  if (N / B == 0) {
    ll x = N;
    ll ax_b = (A * x) / B;
    ll x_b = x / B;
    max_num = max(max_num, ax_b - A * x_b);
  } else {
    for (size_t i = 1; i <= N / B; i++) {
      // ll ax_b = (A * i)/B;
      // ll x_b = i / B;
      ll x = i * B - 1;
      ll ax_b = (A * x) / B;
      ll x_b = x / B;
      max_num = max(max_num, ax_b - A * x_b);
    }
  }
  cout << max_num << endl;
#ifdef TEST
  end = chrono::system_clock::now();
  cerr << static_cast<double>(
              chrono::duration_cast<chrono::microseconds>(end - start).count() /
              1000.0)
       << "[ms]" << endl;
#endif
  return 0;
}
Problem p02696 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  long long int a, b, n;
  long long int res = 0;
  cin >> a >> b >> n;
  long long int i = min(n, b - 1);
  res = floor(a * i / b);
  /*
     while (i<=n && (i/b)<1){
         long long int tmp=floor(a*i/b);
         res=max(res,tmp);
         ++i;
     }
  */
  cout << res << endl;
}

Error: TLE

Fixed submission:

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

int main() {
  long long int a, b, n;
  long long int res = 0;
  cin >> a >> b >> n;
  long long int i = 0;

  while (i <= n && (i / b) < 1) {
    long long int tmp = floor(a * i / b);
    res = max(res, tmp);
    ++i;
  }

  cout << res << endl;
}