Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- #define debug(x) 0&&(cout<<#x<<':'<<x<<'\n')
- #define pb emplace_back
- #define REP(i,l,r) for(auto i=(l);i<(r);i++)
- #define ff first
- #define ss second
- using namespace std;
- typedef long long ll;
- typedef pair<ll,ll> pll;
- const ll N = 100000,INF = 1e18;
- int n,k,d,x,tota,totb,mina,minb,cnt,a[N+1] = {};
- vector<int> block;
- void solve(){
- cin >> n >> k >> d;
- REP(i,0,n) cin >> a[i];
- sort(a,a+n);
- block.clear();
- cnt = 1;
- REP(i,1,n){
- if(a[i]-a[i-1] > k)block.pb(cnt),cnt = 1;
- else ++cnt;
- }
- block.pb(cnt);
- x = n/d;
- tota = totb = 0;
- debug(x);
- for(auto len:block){
- //ax+b(x+1)=len,
- mina = (x+1-len%(x+1))%(x+1);
- minb = len%x;
- debug(len),debug(mina),debug(minb);
- if(mina >= 0 && minb >= 0)tota += mina, totb += minb;
- else return cout << "NO\n",void();
- }
- if(tota <= d-n%d && totb <= n%d)cout << "YES\n",void();
- else cout << "NO\n",void();
- }
- signed main(){
- ios::sync_with_stdio(0), cin.tie(0);
- int t;
- cin >> t;
- while(t--)solve();
- }
Advertisement
Add Comment
Please, Sign In to add comment