CF1039A.Timetable
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
There are two bus stops denoted A and B, and there n buses that go from A to B every day. The shortest path from A to B takes t units of time but some buses might take longer paths. Moreover, buses are allowed to overtake each other during the route.
At each station one can find a sorted list of moments of time when a bus is at this station. We denote this list as a1<a2<…<an for stop A and as b1<b2<…<bn for stop B. The buses always depart from A and arrive to B according to the timetable, but the order in which the buses arrive may differ. Let's call an order of arrivals valid if each bus arrives at least t units of time later than departs.
It is known that for an order to be valid the latest possible arrival for the bus that departs at ai is bxi , i.e. xi -th in the timetable. In other words, for each i there exists such a valid order of arrivals that the bus departed i -th arrives xi -th (and all other buses can arrive arbitrary), but there is no valid order of arrivals in which the i -th departed bus arrives (xi+1) -th.
Formally, let's call a permutation p1,p2,…,pn valid, if bpi≥ai+t for all i . Then xi is the maximum value of pi among all valid permutations.
You are given the sequences a1,a2,…,an and x1,x2,…,xn , but not the arrival timetable. Find out any suitable timetable for stop B b1,b2,…,bn or determine that there is no such timetable.
输入格式
The first line of the input contains two integers n and t ( 1≤n≤200000 , 1≤t≤1018 ) — the number of buses in timetable for and the minimum possible travel time from stop A to stop B.
The second line contains n integers a1,a2,…,an ( 1≤a1<a2<…<an≤1018 ), defining the moments of time when the buses leave stop A.
The third line contains n integers x1,x2,…,xn ( 1≤xi≤n ), the i -th of them stands for the maximum possible timetable position, at which the i -th bus leaving stop A can arrive at stop B.
输出格式
If a solution exists, print "Yes" (without quotes) in the first line of the output.
In the second line print n integers b1,b2,…,bn ( 1≤b1<b2<…<bn≤3⋅1018 ). We can show that if there exists any solution, there exists a solution that satisfies such constraints on bi . If there are multiple valid answers you can print any of them.
If there is no valid timetable, print "No" (without quotes) in the only line of the output.
输入输出样例
输入#1
3 10 4 6 8 2 2 3
输出#1
Yes 16 17 21
输入#2
2 1 1 2 2 1
输出#2
No
说明/提示
Consider the first example and the timetable b1,b2,…,bn from the output.
To get x1=2 the buses can arrive in the order (2,1,3) . To get x2=2 and x3=3 the buses can arrive in the order (1,2,3) . x1 is not 3 , because the permutations (3,1,2) and (3,2,1) (all in which the 1 -st bus arrives 3 -rd) are not valid (sube buses arrive too early), x2 is not 3 because of similar reasons.