Advertisement
Rofyda_Elghadban1

Untitled

Feb 24th, 2024
582
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.61 KB | None | 0 0
  1.  void solve(){
  2.   int n,k,idx=0,counter=0,counter1=0,num=0;
  3.   cin>>n>>k;
  4.   vector<int>a(n),b(n);
  5.   cin(a);
  6.   cin(b);
  7.   vector<pair<int,pair<int,int>>>v;
  8.   vector<pair<int,int>>ans;
  9.   for(int i=0;i<n;i++){
  10.     v.push_back({abs(b[i]),{b[i],a[i]}});
  11.   }
  12.   sort(all(v));
  13.   int z=0;
  14.   // for(int i=0;i<v.size();i++){
  15.   //   cout<<v[i].first<<" "<<v[i].second.first<<" "<<v[i].second.second<<"\n";
  16.   // }
  17.   // cout<<"\n";
  18.   for(int i=0;i<v.size();i++){
  19.     if(z>0){
  20.       if(v[i].second.second<=z){
  21.         z-=v[i].second.second;
  22.         v[i].second.second=0;
  23.       }else{
  24.         // ll m=v[i].second.second-z;
  25.         v[i].second.second-=z;
  26.         z=0;
  27.       }
  28.     }
  29.     if(v[i].second.second>0&&v[i].second.second<=k){
  30.       z+=(k-v[i].second.second);
  31.       // k=k+(k-v[i].second.second);
  32.       counter1++;
  33.     }else if(v[i].second.second>0&&v[i].second.second>k){
  34.       // if(counter==0){
  35.       //   idx=i;
  36.       //   counter++;
  37.       // }
  38.       if(v[i].second.first<0){
  39.         num=v[i].second.first;
  40.         v[i].second.first+=counter1;
  41.         v[i].second.first++;
  42.         ans.emplace_back(num,v[i].second.first);
  43.       }else{
  44.         num=v[i].second.first;
  45.         v[i].second.first-=counter1;
  46.         v[i].second.first--;
  47.         ans.emplace_back(num,v[i].second.first);
  48.       }
  49.       counter1++;
  50.     }
  51.   }
  52.   for(int i=0;i<ans.size();i++){
  53.     cout<<ans[i].second<<" "<<ans[i].first<<"\n";
  54.     if(ans[i].first>0&&ans[i].second<=0){
  55.       cout<<"NO"<<"\n";
  56.       return;
  57.     }else if(ans[i].first<0&&ans[i].second>=0){
  58.       cout<<"NO"<<"\n";
  59.       return;
  60.     }
  61.   }
  62.   cout<<"YES"<<"\n";
  63.  }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement