#include<bits/stdc++.h>
using namespace std;
int order[300007];
long long t[300007],ans[300007];
int main(){
    int n;
    long long m;
 scanf("%d%lld",&n,&m);
 for(int i=1;i<=n;i++)
  scanf("%lld",&t[i]);
 t[n+1]=2e18;
 for(int i=1;i<=n;i++)
  scanf("%d",&order[i]);
 for(int i=1;i<=n;i++)
  if(order[i]<i)
   return puts("No"),0;
 for(int i=1;i<n;i++)
  if(order[i]>order[i+1])
   return puts("No"),0;
 for(int i=n;i>0;i--)
  ans[order[i]]=t[order[i]+1]+m-1;//从后往前是为了尽可能放大空间
 for(int i=n;i>0;i--)
  if(!ans[i])
   ans[i]=ans[i+1]-1;//贪心
 for(int i=1;i<n;i++)
  if((order[i]>i)&&(ans[i]-t[i+1]<m))//出现相同order的话,要能够让后面的前进一个,所以如果不给后面留空间那就不符合题意
   return puts("No"),0;
 puts("Yes");
 for(int i=1;i<=n;i++)
  printf("%lld ",ans[i]);
 return 0;
}

Codeforces Round #507 (Div. 2)C(贪心,逆向遍历,构造)的更多相关文章

  1. Codeforces Round #275 (Div. 2) C - Diverse Permutation (构造)

    题目链接:Codeforces Round #275 (Div. 2) C - Diverse Permutation 题意:一串排列1~n.求一个序列当中相邻两项差的绝对值的个数(指绝对值不同的个数 ...

  2. Codeforces Round #546 (Div. 2) D 贪心 + 思维

    https://codeforces.com/contest/1136/problem/D 贪心 + 思维 题意 你面前有一个队列,加上你有n个人(n<=3e5),有m(m<=个交换法则, ...

  3. Codeforces Round #547 (Div. 3) F 贪心 + 离散化

    https://codeforces.com/contest/1141/problem/F2 题意 一个大小为n的数组a[],问最多有多少个不相交的区间和相等 题解 离散化用值来做,贪心选择较前的区间 ...

  4. Codeforces Round #595 (Div. 3)D1D2 贪心 STL

    一道用STL的贪心,正好可以用来学习使用STL库 题目大意:给出n条可以内含,相交,分离的线段,如果重叠条数超过k次则为坏点,n,k<2e5 所以我们贪心的想我们从左往右遍历,如果重合部分条数超 ...

  5. Codeforces Round #554 (Div. 2) D 贪心 + 记忆化搜索

    https://codeforces.com/contest/1152/problem/D 题意 给你一个n代表合法括号序列的长度一半,一颗有所有合法括号序列构成的字典树上,选择最大的边集,边集的边没 ...

  6. Codeforces Round #303 (Div. 2) D 贪心

    D. Queue time limit per test 1 second memory limit per test 256 megabytes input standard input outpu ...

  7. Codeforces Round #545 (Div. 2) D 贪心 + kmp

    https://codeforces.com/contest/1138/problem/D 题意 两个01串s和t,s中字符能相互交换,问最多能得到多少个(可交叉)的t 题解 即将s中的01塞进t中, ...

  8. Codeforces Round #507 Div. 1

    D:类似于noip2018d1t3,子树内的链应该贪心的尽量合并而不是拆开.则设f[i]为i子树内满足选的链尽量多的情况下根所在的链的最长长度即可.于是可以线性对某个k求得答案. 注意到长度为k的链不 ...

  9. Codeforces Round #547 (Div. 3) G 贪心

    https://codeforces.com/contest/1141/problem/G 题意 在一棵有n个点的树上给边染色,连在同一个点上的边颜色不能相同,除非舍弃掉这个点,问最少需要多少种颜色来 ...

随机推荐

  1. Python — pandas

    Pandas有两种数据结构:Series和DataFrame. 1.Series Series类似于一维数组,和numpy的array接近,由一组数据和数据标签组成.数据标签有索引的作用.数据标签是p ...

  2. define的用法与注意事项

    ------------------------------------------------- 在编程使用宏替换时,当字符串中不只一个符号时,加上括号表现出优先级, 如果是带参数的宏定义,则要给宏 ...

  3. mq_学习_00_资源帖

    一.精选 二.参考资料-基础 JMS(Java消息服务)入门教程 Sun Java System Message Queue 3.7 UR1 技术概述 消息队列-推/拉模式学习 & Activ ...

  4. Struts2 - 运行流程分析

    1. 请求发送给 StrutsPrepareAndExecuteFilter 2. StrutsPrepareAndExecuteFilter 询问 ActionMapper: 该请求是否是一个 St ...

  5. 设计模式 之 《观察者模式 (Observer)》

    #ifndef __OBSERVER_MODEL__ #define __OBSERVER_MODEL__ #include <string> #include <iostream& ...

  6. [原]NYOJ-无线网络覆盖-199

    大学生程序代写 /*无线网络覆盖 时间限制:3000 ms  |  内存限制:65535 KB 难度:3 描述 我们的乐乐同学对于网络可算得上是情有独钟,他有一个计划,那就是用无线网覆盖郑州大学. 现 ...

  7. 1068 Find More Coins (30)(30 分)

    Eva loves to collect coins from all over the universe, including some other planets like Mars. One d ...

  8. 【LeetCode】033. Search in Rotated Sorted Array

    题目: Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand. ( ...

  9. Operating System-Thread(1)What and Why Thread &&进程和线程的对比

    开始线程(Thread)之旅,作为程序员,打交道更多的是线程,各种多线程程序,并行编程都是以线程为基础进行的.本文主要内容: What and Why Thread 进程和线程的对比 一.What a ...

  10. Android TextView跑马灯

    <TextView android:layout_width="fill_parent" android:layout_height="wrap_content&q ...