bingxuan9112

認證考pE

Dec 11th, 2019
285
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.10 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. #define debug(x) 0&&(cout<<#x<<':'<<x<<'\n')
  3. #define pb emplace_back
  4. #define REP(i,l,r) for(auto i=(l);i<(r);i++)
  5. #define ff first
  6. #define ss second
  7.  
  8. using namespace std;
  9. typedef long long ll;
  10. typedef pair<ll,ll> pll;
  11. const ll N = 100000,INF = 1e18;
  12.  
  13. int n,k,d,x,tota,totb,mina,minb,cnt,a[N+1] = {};
  14. vector<int> block;
  15. void solve(){
  16.     cin >> n >> k >> d;
  17.     REP(i,0,n) cin >> a[i];
  18.     sort(a,a+n);
  19.     block.clear();
  20.     cnt = 1;
  21.     REP(i,1,n){
  22.         if(a[i]-a[i-1] > k)block.pb(cnt),cnt = 1;
  23.         else ++cnt;
  24.     }
  25.     block.pb(cnt);
  26.     x = n/d;
  27.     tota = totb = 0;
  28.     debug(x);
  29.     for(auto len:block){
  30.         //ax+b(x+1)=len,
  31.         mina = (x+1-len%(x+1))%(x+1);
  32.         minb = len%x;
  33.         debug(len),debug(mina),debug(minb);
  34.         if(mina >= 0 && minb >= 0)tota += mina, totb += minb;
  35.         else return cout << "NO\n",void();
  36.     }
  37.     if(tota <= d-n%d && totb <= n%d)cout << "YES\n",void();
  38.     else cout << "NO\n",void();
  39. }
  40. signed main(){
  41.     ios::sync_with_stdio(0), cin.tie(0);
  42.     int t;
  43.     cin >> t;
  44.     while(t--)solve();
  45. }
Advertisement
Add Comment
Please, Sign In to add comment