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

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 
#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;
}

原文地址:https://www.cnblogs.com/Shallow-dream/p/11620911.html

时间: 2024-07-31 23:44:52

E Minimum Array ( Codeforces Round #555 (Div. 3) )的相关文章

Codeforces Round #555 (Div. 3)[1157]题解

不得不说这场div3是真的出的好,算得上是从我开始打开始最有趣的一场div3.因为自己的号全都蓝了,然后就把不经常打比赛的dreagonm的号借来打这场,然后...比赛结束rank11(帮dreagonm上蓝果然没有食言qwq). (震惊...HA省A队CF青名...) CF1157A Reachable Numbers 水题,分析一下不难发现不超过\(10\)次就会少一位,然后\(10^9\)范围内的数可以到达的数个数显然不多,不妨大力模拟,然后把出现的数扔进set,最后输出set.size(

Codeforces Round #555 Div. 3

题目链接:戳我 完了,最菜就是我了.div.3都写不动QAQ A 按照题意模拟即可,注意判重 #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<cmath> #include<vector> #include<map> #define MAXN 100010 using namespace std; int

Codeforces Round # 555 (Div. 3) C2. Increasing subsequence (complicated version) (贪心)

题目链接:http://codeforces.com/contest/1157/problem/C2 当左右两边数字相同时,需要判断一下取哪边能得到更长的递增序列 #include <iostream> #include <cstring> #include <algorithm> #include <cmath> #include <cstdio> #include <queue> #include <climits>

Codeforces Round #555 (Div. 3) A B C1(很水的题目)

A. Reachable Numbers 题意:设f(x)为 x+1 这个数去掉后缀0的数,现在给出n,问经过无数次这种变换后,最多能得到多少个不同的数. 代码 #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> #include<queue> #include<stack> #include<set> #include<

Codeforces Round #258 (Div. 2) B. Sort the Array(简单题)

题目链接:http://codeforces.com/contest/451/problem/B ---------------------------------------------------------------------------------------------------------------------------------------------------------- 欢迎光临天资小屋:http://user.qzone.qq.com/593830943/ma

Codeforces Round #251 (Div. 2) C. Devu and Partitioning of the Array

注意p的边界情况,p为0,或者 p为k 奇数+偶数 = 奇数 奇数+奇数 = 偶数 #include <iostream> #include <vector> #include <set> #include <algorithm> #include <cmath> using namespace std; int main(){ int n,k,p; long a; cin >> n >> k >> p; ve

[Codeforces Round #617 (Div. 3)] 题解 A,B,C,D,E1,E2,F

[Codeforces Round #617 (Div. 3)] 题解 A,B,C,D,E1,E2,F 1296A - Array with Odd Sum 思路: 如果一开始数组的sum和是奇数,那么直接YES, 否则:如果存在一个奇数和一个偶数,答案为YES,否则为NO 代码: int n; int a[maxn]; int main() { //freopen("D:\\code\\text\\input.txt","r",stdin); //freopen(

Codeforces Round #315 (Div. 1)

A. Primes or Palindromes? time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output Rikhail Mubinchik believes that the current definition of prime numbers is obsolete as they are too complex and un

Codeforces Round #354 (Div. 2) ABCD

Codeforces Round #354 (Div. 2) Problems # Name     A Nicholas and Permutation standard input/output 1 s, 256 MB    x3384 B Pyramid of Glasses standard input/output 1 s, 256 MB    x1462 C Vasya and String standard input/output 1 s, 256 MB    x1393 D T