题目链接;http://codeforces.com/problemset/problem/761/D点击打开链接
ci=bi-ai
pi为ci在c数组中为第pi小个
给你p数组和a数组 构造b数组且范围不可超过l~r
我们从最小的ci开始 为了使后面更有空间构造 从范围的左端点开始构造b数组 当碰见某个b小于范围l时 将最小值加至l
如果超过r则说明无法构造 因为此时构造已为c数组的最小情况
#include <bits/stdc++.h>
using namespace std;
int n,l,r;
struct xjy
{
int a;
int num;
int pos;
int b;
bool operator < (const xjy &r)const
{
return num<r.num;
}
};
bool cmp1(xjy a1,xjy a2)
{
return a1.pos<a2.pos;
}
vector<xjy > s;
int main()
{
cin >> n >>l >>r;
for(int i=0;i<n;i++)
{
xjy mid;
cin >> mid.a;
mid.pos=i;
s.push_back(mid);
}
for(int i=0;i<n;i++)
cin >> s[i].num;
sort(s.begin(),s.end());
int mid=0;
int cnt=l-s[0].a;
s[0].b=cnt+s[0].a;
cnt++;
for(int i=1;i<n;i++)
{
s[i].b=cnt+s[i].a;
cnt++;
if(s[i].b>r)
{
cout << -1 ;
return 0;
}
if(s[i].b<l)
{
mid=max(mid,l-s[i].b);
}
}
sort(s.begin(),s.end(),cmp1);
for(int i=0;i<n;i++)
{
if(s[i].b+mid>r)
{
cout << "-1" <<endl;
return 0;
}
}
for(int i=0;i<n;i++)
cout <<s[i].b+mid << " ";
}