Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void solve(){
- int n,k,idx=0,counter=0,counter1=0,num=0;
- cin>>n>>k;
- vector<int>a(n),b(n);
- cin(a);
- cin(b);
- vector<pair<int,pair<int,int>>>v;
- vector<pair<int,int>>ans;
- for(int i=0;i<n;i++){
- v.push_back({abs(b[i]),{b[i],a[i]}});
- }
- sort(all(v));
- int z=0;
- // for(int i=0;i<v.size();i++){
- // cout<<v[i].first<<" "<<v[i].second.first<<" "<<v[i].second.second<<"\n";
- // }
- // cout<<"\n";
- for(int i=0;i<v.size();i++){
- if(z>0){
- if(v[i].second.second<=z){
- z-=v[i].second.second;
- v[i].second.second=0;
- }else{
- // ll m=v[i].second.second-z;
- v[i].second.second-=z;
- z=0;
- }
- }
- if(v[i].second.second>0&&v[i].second.second<=k){
- z+=(k-v[i].second.second);
- // k=k+(k-v[i].second.second);
- counter1++;
- }else if(v[i].second.second>0&&v[i].second.second>k){
- // if(counter==0){
- // idx=i;
- // counter++;
- // }
- if(v[i].second.first<0){
- num=v[i].second.first;
- v[i].second.first+=counter1;
- v[i].second.first++;
- ans.emplace_back(num,v[i].second.first);
- }else{
- num=v[i].second.first;
- v[i].second.first-=counter1;
- v[i].second.first--;
- ans.emplace_back(num,v[i].second.first);
- }
- counter1++;
- }
- }
- for(int i=0;i<ans.size();i++){
- cout<<ans[i].second<<" "<<ans[i].first<<"\n";
- if(ans[i].first>0&&ans[i].second<=0){
- cout<<"NO"<<"\n";
- return;
- }else if(ans[i].first<0&&ans[i].second>=0){
- cout<<"NO"<<"\n";
- return;
- }
- }
- cout<<"YES"<<"\n";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement