Advertisement
Rofyda_Elghadban1

Untitled

Feb 5th, 2024
881
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.99 KB | None | 0 0
  1.  #include <bits/stdc++.h>
  2.  #define ll long long
  3.  #define ull unsigned long long
  4.  #define pi 3.141592654
  5.  #define NUM 1e18
  6.  #define Mod  1'000'000'007
  7.  #define fixed(n) fixed<<setprecision(n)
  8.  #define cin(v) for(auto &i:v) cin >> i ;
  9.  #define cout(v) for(auto &i:v) cout << i  <<" ";
  10.  #define vowel(x) (x=='e'||x=='a'||x=='i'||x=='o'||x=='u')
  11.  #define small(x) (x>=97&&x<=122)
  12.  #define capital(x) (x>=65&&x<=90)
  13.  #define Tolower(s) transform(s.begin(),s.end(),s.begin(),::tolower);
  14.  #define Toupper(s) transform(s.begin(),s.end(),s.begin(),::toupper);
  15.  #define sz(x) (int)(x.size())
  16.  #define all(v) ((v).begin()), ((v).end())
  17.  #define allr(v) ((v).rbegin()), ((v).rend())
  18.  #define updmax(a,b) a=max(a,b)
  19.  #define updmin(a,b) a=min(a,b)
  20.  #define ceil(a,b) ((a/b)+(a%b?1:0))
  21.  /* asc -> 1 2 3 ,des -> 3 2 1 */
  22.  /***********************************************************************************/
  23.  using namespace std;
  24.  void Rofyda_Elghadban(){
  25.   #ifndef ONLINE_JUDGE  
  26.     freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
  27.    #endif
  28.     ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  29.  }
  30.  
  31.  void solve(){
  32.   ll n,m,k;
  33.   cin>>n>>m>>k;
  34.   vector<ll>v(n),v1;
  35.   cin(v);
  36.   v1=v;
  37.   sort(all(v));
  38.   map<ll,ll>mp;
  39.   ll l=0,r=1e9,ans=-1,counter=1,d=0,idx=0,temp=v[0],res=-1;
  40.   for(int i=0;i<v.size();i++){
  41.     if(i==0){
  42.       mp[v[i]]=counter;
  43.     }else{
  44.       if(v[i]-temp>k){
  45.         counter=1;
  46.         mp[v[i]]=counter;
  47.         temp=v[i];
  48.         d=i-idx;
  49.         ans=max(ans,d);
  50.         idx=i;
  51.       }else{
  52.         counter++;
  53.         mp[v[i]]=counter;
  54.         continue;
  55.       }
  56.     }
  57.   }
  58.   while(l<=r){
  59.     ll mid=l+(r-l)/2;
  60.     if(mid>=ans){
  61.       res=mid;
  62.       r=mid-1;
  63.     }else{
  64.       l=mid+1;
  65.     }
  66.   }
  67.   cout<<res<<"\n";
  68.   v=v1;
  69.   for(int i=0;i<n;i++){
  70.     cout<<mp[v[i]]<<" ";
  71.   }
  72.  }
  73.  
  74.  int main(){
  75.   Rofyda_Elghadban();
  76.   // int t;
  77.   // cin>>t;
  78.   // while(t--){
  79.   //   solve();
  80.   // }
  81.   solve();
  82.   return 0;
  83.  }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement