I - Minimum Array CodeForces - 1157E (思维)

You are given two arrays aa and bb, both of length nn. All elements of both arrays are from 00 to n−1n−1.

You can reorder elements of the array bb (if you want, you may leave the order of elements as it is). After that, let array cc be the array of length nn, the ii-th element of this array is ci=(ai+bi)%nci=(ai+bi)%n, where x%yx%y is xx modulo yy.

Your task is to reorder elements of the array bb to obtain the lexicographicallyminimum possible array cc.

Array xx of length nn is lexicographically less than array yy of length nn, if there exists such ii (1≤i≤n1≤i≤n), that xi<yixi<yi, and for any jj (1≤j<i1≤j<i) xj=yjxj=yj.

Input

The first line of the input contains one integer nn (1≤n≤2⋅1051≤n≤2⋅105) — the number of elements in aa, bb and cc.

The second line of the input contains nn integers a1,a2,…,ana1,a2,…,an (0≤ai<n0≤ai<n), where aiaiis the ii-th element of aa.

The third line of the input contains nn integers b1,b2,…,bnb1,b2,…,bn (0≤bi<n0≤bi<n), where bibi is the ii-th element of bb.

Output

Print the lexicographically minimum possible array cc. Recall that your task is to reorder elements of the array bb and obtain the lexicographically minimum possible array cc, where the ii-th element of cc is ci=(ai+bi)%nci=(ai+bi)%n.

Examples

Input

4
0 1 2 1
3 2 1 1

Output

1 0 0 2 

Input

7
2 5 1 5 3 4 3
2 4 3 5 6 5 1

Output

0 0 0 1 0 2 4 

代码:


//Full of love and hope for life

#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <queue>
#include <vector>
#include <bits/stdc++.h>
#define inf 0x3f3f3f3f
//https://paste.ubuntu.com/
//https://www.cnblogs.com/zzrturist/    //博客园
//https://blog.csdn.net/qq_44134712     //csdn

using namespace std;
const int N=5e3+10;
typedef long long ll;
const int mod=1e9+7;

int a[200010],b[200010],c[200010];
multiset<int>s;

int main() {
   int n;
   cin >> n;
   for(int i=1;i<=n;i++) {
      cin >> a[i];
   }
   for(int i=1;i<=n;i++) {
      cin >> b[i];
      s.insert(b[i]);
   }
   multiset<int>::iterator it;
   for(int i=1;i<=n;i++) {
      int need=n-a[i];
      it=s.lower_bound(need);
      if(it==s.end()) {
         it=s.begin();
      }
      c[i]=(*it+a[i])%n;
      s.erase(it);
   }
   for(int i=1;i<=n;i++) {
        if(i==n){
            cout << c[i];
        }
        else{
            cout << c[i] << " ";
        }
   }
   return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

ZZ --瑞 hopeACMer

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值