-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathChef Lost an Array
103 lines (88 loc) Β· 2.56 KB
/
Chef Lost an Array
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<ll> vll;
#define PI (2*acos(0.0))
#define eps 1e-9
#define pb push_back
#define endl "\n"
#define watch(x) cout << (#x) << " is " << (x) << endl;
#define show(v) for(int fi = 0; fi < v.size(); fi++) cout << v[fi] << " "; cout << endl;
#define showpair(v) for(int fi = 0; fi < v.size(); fi++) cout << v[fi].first << " " << v[fi].second << endl;
#define ff first
#define ss second
#define fu cout << "lol" << endl;
#define precision(n) cout << fixed << setprecision(n);
#define lb lower_bound
#define up upper_bound
#define all(a) a.begin(), a.end()
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define mem(a,val) memset(a,val,sizeof(a))
#define TC ull T; cin>>T; while(T--)
#define IN(x) {scanf("%d",&x);}
#define LL(x) {scanf("%lld",&x);}
#define CC(x) {scanf("%c",&x);}
#define pfl(x) printf("%d\n",x)
#define pfll(x) printf("%lld\n",x)
#define newl puts("")
#define space printf(" ")
#define MOD 1000000007
#define speed ios_base::sync_with_stdio(false); cin.tie(NULL);
#define ar array
/*
3 3
4 4 5
4 2 2
1. mx[0] = mn[0] = ans[0]
2. mx[i] == mx[i-1], a[i] <= mx[i]
mn[i] == mn[i-1], a[i] >= mn[i]
3.
*/
void solve(){
TC{
ll n, d; cin>>n>>d;
vll mx(n), mn(n), nxt(n), ans(n);
for(int i = 0; i < n; i++) cin>>mx[i];
for(int i = 0; i < n; i++) cin>>mn[i];
ll c = 0;
for(int i = n-1; ~i; i--){
if(mx[i] != mx[i-1]) nxt[i] = 1;
else if(mn[i] != mn[i-1]) nxt[i] = -1;
else if(i < n-1) nxt[i] = nxt[i+1];
}
ans[0] = mx[0];
for(int i = 1; i < n; i++){
if(mx[i] != mx[i-1]) ans[i] = mx[i];
else if(mn[i] != mn[i-1]) ans[i] = mn[i];
else{
if(nxt[i] == 1) ans[i] = min(ans[i-1]+d, mx[i]);
else if(nxt[i] == -1) ans[i] = max(ans[i-1]-d, mn[i]);
else ans[i] = ans[i-1];
}
}
ll ok = 1;
if(mx[0] != mn[0]) ok = 0;
for(int i = 1; i < n; i++){
ok &= mx[i-1]<=mx[i];
ok &= mn[i-1]>=mn[i];
ok &= !(mx[i-1] != mx[i] && mn[i-1] != mn[i]);
ok &= llabs(ans[i]-ans[i-1])<=d;
}
if(ok){
cout << "YES" << endl;
for(int i = 0; i < n; i++) cout << ans[i] << " "; cout << endl;
}
else cout << "NO" << endl;
}
}
int main()
{
speed;
solve();
return 0;
}