Source Code
/// Zengy Manga
#pragma GCC optimize("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx,avx2,fma")
using namespace std;

#include "bits/stdc++.h"
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/rope>

using namespace __gnu_pbds;
using namespace __gnu_cxx;

using ll = long long;
using ii = pair<int, int>;

template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define pb push_back
#define F first
#define S second
#define f(i, a, b)  for(int i = a; i < b; i++)
#define all(a)  a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define sz(x) (int)(x).size()
#define mp make_pair
#define popCnt(x) (__builtin_popcountll(x))
#define int ll

const int N = 1e6+5, LG = log2(N) + 1, MOD = 1e9 + 7;
const double PI = acos(-1);
void doWork() {

    int n, k, e;
    cin >> n >> e >> k;
    if(e >= n - 1 || k - 1 >= n) {
        cout << "Yes\n";
        return;
    }
    int pos = 1 + e;
    int val = 1 +  (pos - (k - 1)) / k;  ///value of the one I am taking
    int lft = (val == 1 ? k - 1 : k);
    int nxt = val * k; ///next higher level candy
    int diff = nxt - pos; ///number of people that will take from this
    int cur = diff + 1; ///first person that will take from the new candy
    lft -= (diff);  ///what is left from the current candy
    cur += (n - nxt + 1);   ///first person that will need to eat from lft

    if(val == 1) {
        if(lft == 0 || cur-e >= 1) {
            cout << "Yes\n";
        }   else {
            cout << "No\n";
        }
    }   else {
        if(lft == 0) {
            val -= 1;
            lft = (val == 1 ? k - 1 : k);
        }
        if(val == 1) {
            if(cur - e >= 1) {
                cout << "Yes\n";
            }   else {
                cout << "No\n";
            }
        }   else {
            cur += lft;
            cur += (val - 2) * k;
            if(cur - e >= 1) {
                cout << "Yes\n";
            }   else {
                cout << "No\n";
            }
        }
    }




}
int32_t main() {
#ifdef ONLINE_JUDGE
    ios_base::sync_with_stdio(0);
    cin.tie(0);
#endif // ONLINE_JUDGE

    int t = 1;
//    cin >> t;
    while (t--) {
        doWork();
    }


    return 0;
}
Copy
Scientific Study DeadlyPillow
GNU G++17
2 ms
920 KB
Wrong Answer