a aand b "> b b, both of length n "> n n. All elements of both arrays are from 0 "> 0 0to n #x2212; 1 "> n − 1 n−1. You can reorder elements of the array b "> b b(if you want, you may leave the order of ele" />

当前位置 : 主页 > 网页制作 > css >

E Minimum Array ( Codeforces Round #555 (Div. 3) )

来源:互联网 收集:自由互联 发布时间:2021-06-13
You are given two arrays a "> a aand b "> b b, both of length n "> n n. All elements of both arrays are from 0 "> 0 0to n #x2212; 1 "> n − 1 n−1. You can reorder elements of the array b "> b b(if you want, you may leave the order of ele

 

You are given two arrays aa and bb, both of length nn. All elements of both arrays are from 00 to n1n−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 (1in1≤i≤n), that xi<yixi<yi, and for any jj (1j<i1≤j<i) xj=yjxj=yj.

Input

The first line of the input contains one integer nn (1n21051≤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 (0ai<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 (0bi<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 

 

#include <iostream> #include <algorithm> #include <cstdio> #include <string> #include <cstring> #include <cstdlib> #include <map> #include <vector> #include <set> #include <queue> #include <stack> #include <cmath> // #define lson rt<<1, l, m #define rson rt<<1|1, m+1, r // #define fi first #define se second #define pb push_back #define pq priority_queue<int> #define ok return 0; #define os(str) cout<<string(str)<<endl; #define gcd __gcd #define mem(s,t) memset(s,t,sizeof(s)) #define debug(a,n) for(int i=0;i<n;i++) cout<<a[i]<<" "; cout<<endl; #define debug1(a,n) for(int i=1;i<=n;i++) cout<<a[i]<<" "; cout<<endl; #define debug02(a,n,m) for(int i=0;i<n;i++) {for(int j=0;j<m;j++) cout<<a[i][j]<<" "; cout<<endl; } #define read11(a,k) for (int i = 1; i <= (int)(k); i++) {cin>>a[i];} #define read02(a,n,m) for(int i=0;i<n;i++) {for(int j=0;j<m;j++) cin>>a[i][j] ; } #define TLE std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cout.precision(10); using namespace std; inline void NO() { cout<<"NO"<<endl; } inline void YES() { cout<<"YES"<<endl; } const int mxn = 2e5+10; #define oi(x) cout<<x<<endl; #define rep(k) for (int i=0;i<n;i++) #define rep1(j,k) for (int i=j;i<=k; i++) #define per(j,k) for (int i=j;i>=k; i--) #define test cout<<" +++++++ "<<endl; multiset<int> v; multiset<int> :: iterator it ; int main() { int n,b; cin>>n; int a[n+5]; for(int i=0; i<n; i++) cin>>a[i]; for(int i=0; i<n; i++) { cin>>b; v.insert(b); } for(int i=0; i<n; i++) { int p = n-a[i]; it = v.lower_bound(p); if(it==v.end()) it = v.begin(); cout<<(a[i]+(*it))%n<<" "; v.erase(it); } cout<<endl; return 0; }
网友评论