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

#include <bits/stdc++.h>
// #include <boost/array.hpp>
// #include <boost/range/numeric.hpp>
// #include <boost/range/algorithm.hpp>
// #include <boost/multiprecision/cpp_int.hpp>

#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace std;
// using namespace boost::multiprecision;

constexpr long long INF = LLONG_MAX;
constexpr long long MOD = 1000000007;
constexpr long double PI = M_PI;

#define FOR(i, r, n) for (ll i = (ll)(r); i < (ll)(n); ++i)
#define RFOR(i, n, r) for (ll i = (ll)(n - 1); i >= r; --i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
#define ALL(x) x.begin(), x.end()
#define CALL(x) x.cbegin(), x.cend()
#define RALL(x) x.rbegin(), x.rend()
#define CRALL(x) x.crbegin(), x.crend()

#define cout cout << fixed << setprecision(12)
#define dbglf cerr << '\\n'

#define ACCM(arr) accumulate(ALL(arr), 0LL)
#define Yes(ex) cout << ((ex) ? "Yes" : "No") << endl
#define YES(ex) cout << ((ex) ? "YES" : "NO") << endl

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using vi = vector<ll>;
using vvi = vector<vi>;
using vp = vector<pair<ll, ll>>;
using vs = vector<string>;
using vc = vector<char>;
using lst = list<ll>;
using pq = priority_queue<ll>;

template <typename T> inline void veccin(vector<T> &v) {
  for (auto &&e : v) {
    cin >> e;
  }
}

template <typename T> inline void dbg(T a) { cerr << a << ' '; }

ll n, m, k;
ll ans = 0, sum = 0, cnt = 0;
// ld d;
string s /*1, s2, s3*/;
char c /*1, c2, c3*/;
bool flag = false;

/*--------------------template--------------------*/

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

  cin >> n >> m >> k;
  ans = floor(n * (m - 1) / m) - n * floor((m - 1) / m);
  sum = floor(n * k / m) - n * floor(k / m);
  cout << (m > k ? sum : ans) << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
// #include <boost/array.hpp>
// #include <boost/range/numeric.hpp>
// #include <boost/range/algorithm.hpp>
// #include <boost/multiprecision/cpp_int.hpp>

#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace std;
// using namespace boost::multiprecision;

constexpr long long INF = LLONG_MAX;
constexpr long long MOD = 1000000007;
constexpr long double PI = M_PI;

#define FOR(i, r, n) for (ll i = (ll)(r); i < (ll)(n); ++i)
#define RFOR(i, n, r) for (ll i = (ll)(n - 1); i >= r; --i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
#define ALL(x) x.begin(), x.end()
#define CALL(x) x.cbegin(), x.cend()
#define RALL(x) x.rbegin(), x.rend()
#define CRALL(x) x.crbegin(), x.crend()

#define cout cout << fixed << setprecision(12)
#define dbglf cerr << '\\n'

#define ACCM(arr) accumulate(ALL(arr), 0LL)
#define Yes(ex) cout << ((ex) ? "Yes" : "No") << endl
#define YES(ex) cout << ((ex) ? "YES" : "NO") << endl

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using vi = vector<ll>;
using vvi = vector<vi>;
using vp = vector<pair<ll, ll>>;
using vs = vector<string>;
using vc = vector<char>;
using lst = list<ll>;
using pq = priority_queue<ll>;

template <typename T> inline void veccin(vector<T> &v) {
  for (auto &&e : v) {
    cin >> e;
  }
}

template <typename T> inline void dbg(T a) { cerr << a << ' '; }

ll n, m, k;
ll ans = 0, sum = 0, cnt = 0;
// ld d;
string s /*1, s2, s3*/;
char c /*1, c2, c3*/;
bool flag = false;

/*--------------------template--------------------*/

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

  cin >> n >> m >> k;
  RREP(i, k) {
    dbg(floor(n * (i + 1) / m) - n * floor((i + 1) / m));
    dbglf;
  }
  ans = floor(n * (m - 1) / m) - n * floor((m - 1) / m);
  sum = floor(n * k / m) - n * floor(k / m);
  cout << (m > k ? sum : ans) << endl;
}