Dasha logged into the system and began to solve problems. One of them is as follows:
Given two sequences a and b of length n each you need to write a sequence c of length n, the i-th element of which is calculated as follows: ci = bi - ai.
About sequences a and b we know that their elements are in the range from l to r. More formally, elements satisfy the following conditions: l ≤ ai ≤ r and l ≤ bi ≤ r. About sequence c we know that all its elements are distinct.
![](https://i-blog.csdnimg.cn/blog_migrate/5b86453b5ec2ef9adb6d9014bb43a0a4.png)
Dasha wrote a solution to that problem quickly, but checking her work on the standard test was not so easy. Due to an error in the test system only the sequence a and the compressed sequence of the sequence c were known from that test.
Let's give the definition to a compressed sequence. A compressed sequence of sequence c of length n is a sequence p of length n, so that pi equals to the number of integers which are less than or equal to ci in the sequence c. For example, for the sequence c = [250, 200, 300, 100, 50] the compressed sequence will be p = [4, 3, 5, 2, 1]. Pay attention that in c all integers are distinct. Consequently, the compressed sequence contains all integers from 1 to n inclusively.
Help Dasha to find any sequence b for which the calculated compressed sequence of sequence c is correct.
The first line contains three integers n, l, r (1 ≤ n ≤ 105, 1 ≤ l ≤ r ≤ 109) — the length of the sequence and boundaries of the segment where the elements of sequences a and b are.
The next line contains n integers a1, a2, ..., an (l ≤ ai ≤ r) — the elements of the sequence a.
The next line contains n distinct integers p1, p2, ..., pn (1 ≤ pi ≤ n) — the compressed sequence of the sequence c.
If there is no the suitable sequence b, then in the only line print "-1".
Otherwise, in the only line print n integers — the elements of any suitable sequence b.
5 1 5 1 1 1 1 1 3 1 5 4 2
3 1 5 4 2
4 2 9 3 4 8 9 3 2 1 4
2 2 2 9
6 1 5 1 1 1 1 1 1 2 3 5 4 1 6
-1
Sequence b which was found in the second sample is suitable, because calculated sequence c = [2 - 3, 2 - 4, 2 - 8, 9 - 9] = [ - 1, - 2, - 6, 0] (note that ci = bi - ai) has compressed sequence equals to p = [3, 2, 1, 4].
[题意]
给 定 B[i] ; C[i] = B[i]-A[i] 现在给出p[i] p[i] 的 定义为 在C[ ]中 比当前这个数小的个数是多少
给定L-R的限制 为 B[i]的可能 输出任意一组就可以
[思路]
完全可以把P[] 当做 C[]数组, B[] 其实就是P[ ] +A[ ] 在L-R中 可以移动的区间数, 在这之间都是可以的.
如果超出移动范围 就没有答案,
在移动区间内, 保证满足最小值大于L,最大值小于R.
[代码实现]
#include <bits/stdc++.h>
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <math.h>
#include <cstring>
#include <string>
#include <queue>
#include <deque>
#include <stack>
#include <stdlib.h>
#include <list>
#include <map>
#include <set>
#include <bitset>
#include <vector>
#define mem(a,b) memset(a,b,sizeof(a))
#define findx(x,b,n) lower_bound(b+1,b+1+n,x)-b
#define FIN freopen("input.txt","r",stdin)
#define FOUT freopen("output.txt","w",stdout)
#define SHUT ios_base::sync_with_stdio(false); cout.setf(ios::fixed); cout.tie(nullptr); cin.tie(nullptr);
#define lson rt << 1, l, mid
#define rson rt << 1|1, mid + 1, r
#define FI(n) IO::read(n)
#define Be IO::begin()
using namespace std;
typedef long long ll;
const double PI=acos(-1);
const int INF=0x3f3f3f3f;
const double esp=1e-6;
const int maxn=1e6+5;
const int MAXN=1e5+5;
const int MOD=1e9+7;
const int mod=1e9+7;
int dir[5][2]={0,1,0,-1,1,0,-1,0};
namespace IO {
const int MT = 5e7;
char buf[MT]; int c,sz;
void begin(){
c = 0;
sz = fread(buf, 1, MT, stdin);//一次性输入
}
template<class T>
inline bool read(T &t){
while( c < sz && buf[c] != '-' && ( buf[c]<'0' || buf[c] >'9')) c++;
if( c>=sz) return false;
bool flag = 0; if( buf[c]== '-') flag = 1,c++;
for( t=0; c<=sz && '0' <=buf[c] && buf[c] <= '9'; c++ ) t= t*10 + buf[c]-'0';
if(flag) t=-t;
return true;
}
}
ll inv[maxn*2];
inline void ex_gcd(ll a,ll b,ll &d,ll &x,ll &y){if(!b){ x=1; y=0; d=a; }else{ ex_gcd(b,a%b,d,y,x); y-=x*(a/b);};}
inline ll gcd(ll a,ll b){ return b?gcd(b,a%b):a;}
inline ll exgcd(ll a,ll b,ll &x,ll &y){if(!b){x=1;y=0;return a;}ll ans=exgcd(b,a%b,x,y);ll temp=x;x=y;y=temp-a/b*y;return ans;}
inline ll lcm(ll a,ll b){ return b/gcd(a,b)*a;}
inline ll qpow(ll x,ll n){ll res=1;for(;n;n>>=1){if(n&1)res=(res*x)%MOD;x=(x*x)%MOD;}return res;}
inline ll inv_exgcd(ll a,ll n){ll d,x,y;ex_gcd(a,n,d,x,y);return d==1?(x+n)%n:-1;}
inline ll inv1(ll b){return b==1?1:(MOD-MOD/b)*inv1(MOD%b)%MOD;}
inline ll inv2(ll b){return qpow(b,MOD-2);}
int a[MAXN];
int b[MAXN];
int p[MAXN];
int main()
{
SHUT;
int n,l,r;
cin>>n>>l>>r;
for(int i=1;i<=n;i++)
cin>>a[i];
for(int i=1;i<=n;i++)
cin>>p[i];
int MAXS=-INF;
int Mins=INF;
for(int i=1;i<=n;i++)
{
b[i]=a[i]+p[i];
MAXS=max(b[i],MAXS);
Mins=min(b[i],Mins);
}
if(MAXS-Mins+1> r-l+1)
{
cout<<-1<<endl;
return 0;
}
else
{
int det;
if(Mins<l)
det=l-Mins;
else
det=r-MAXS;
for(int i=1;i<=n;i++)
{
b[i]+=det;
cout<<b[i]<<" ";
}
cout<<endl;
}
/*
2 1 1000000000
1000000000 1
1 2
*/
return 0;
}