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

4754 단어

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 xiInput
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≤aiThe third line of the input contains nn integers b1,b2,…,bnb1,b2,…,bn (0≤biOutput
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 
#include 
#include 
#include <string>
#include 
#include 
#include 
#include 
#include <set>
#include 
#include 
#include 
//
#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
#define ok      return 0;
#define os(str) cout<#define gcd __gcd
#define mem(s,t) memset(s,t,sizeof(s))
#define debug(a,n) for(int i=0;i#define debug1(a,n) for(int i=1;i<=n;i++) cout<#define debug02(a,n,m) for(int i=0;i#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>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<#define rep(k)    for (int i=0;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<
multiset<int> v;
multiset<int> :: iterator it ;
int main()
{
int n,b;
cin>>n;
int a[n+5];
for(int i=0; i)
cin>>a[i];
for(int i=0; i)
{
cin>>b;
v.insert(b);
}
for(int i=0; i)
{
int p = n-a[i];
it = v.lower_bound(p);
if(it==v.end()) it = v.begin();
cout<" ";
v.erase(it);
}
cout<<endl;
return 0;
}

 

좋은 웹페이지 즐겨찾기