dp[ i ][ 0 ]表示放完前 i 页, 第 i 页最后一段是 0, 0个数的最小值。
dp[ i ][ 1 ]表示放完前 i 页, 第 i 页最后一段是 1, 1个数的最小值。
这个转移细节有点多。。。
#include<bits/stdc++.h>
#define LL long long
#define LD long double
#define fi first
#define se second
#define mk make_pair
#define PLL pair<LL, LL>
#define PLI pair<LL, int>
#define PII pair<int, int>
#define SZ(x) ((int)x.size())
#define ull unsigned long long using namespace std; const int N = 3e5 + ;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + ;
const double eps = 1e-;
const double PI = acos(-); template<class T> bool chkmax(T& a, T b) {
return a < b ? a = b, true : false;
}
template<class T> bool chkmin(T& a, T b) {
return a > b ? a = b, true : false;
} int n, x[N], y[N];
LL k;
int dp[N][]; int calc(int prea, int a, int b, int op) {
if(!op) {
if(k - prea + b * k < a) return inf;
if(a * k < b) return inf;
if(k - prea + (b - ) * k < a - ) return a - (k - prea + (b - ) * k);
return ;
} else {
if(k - prea + (b - ) * k < a) return inf;
if((a + ) * k < b) return inf;
if(a * k < b - ) return b - a * k;
return ;
}
} int main() {
scanf("%d%lld", &n, &k);
for(int i = ; i <= n; i++) scanf("%d", &x[i]);
for(int i = ; i <= n; i++) scanf("%d", &y[i]);
memset(dp, inf, sizeof(dp));
dp[][] = dp[][] = ;
for(int i = ; i < n; i++) {
if(dp[i][] <= k) {
chkmin(dp[i + ][], calc(dp[i][], x[i + ], y[i + ], ));
chkmin(dp[i + ][], calc(dp[i][], x[i + ], y[i + ], ));
}
if(dp[i][] <= k) {
chkmin(dp[i + ][], calc(dp[i][], y[i + ], x[i + ], ));
chkmin(dp[i + ][], calc(dp[i][], y[i + ], x[i + ], ));
}
}
if(dp[n][] > k && dp[n][] > k) {
puts("NO");
} else puts("YES");
return ;
} /*
*/