//#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template <class T>
using Tree =
tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define int long long
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define fi first
#define se second
#define rep(i, a, b) for (int i = a; i <= b; ++i)
#define per(i, b, a) for (int i = b; i >= a; --i)
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(), (v).end()
#define lsb(x) (x)&(-x)
#define bug(x) cerr << #x << " " << x << endl;
void setIO(string name = "") {
ios_base::sync_with_stdio(false);
cin.tie(nullptr); cout.tie(nullptr);
if (!name.empty()) {
freopen((name + ".in").c_str(), "r", stdin);
freopen((name + ".out").c_str(), "w", stdout);
}
}
ll fexp(ll a, ll b, ll m) {
if (b == 0) return 1LL;
ll p = a;
ll ans = 1;
while (b > 0) {
if (b % 2 != 0) ans = (ans * p) % m;
p = (p * p) % m;
b >>= 1;
}
return ans;
}
const int MAXN = 2e3 + 10;
const int INF = 1e18 + 5;
const int MOD = 1e9+7;
pii dp[MAXN][MAXN][2];
void solve() {
int n, L;cin >> n >> L;
deque<int> a(n),t(n);
rep(i,1,n) cin >> a[i-1];
rep(i,1,n) cin >> t[i-1];
int ans = 0;
rep(_,1,n+1) {
rep(i,1,n) {
if (abs(a[i-1])<=t[i-1]) dp[i][i][0] = dp[i][i][1] = {1LL,-abs(a[i-1])};
else dp[i][i][0] = dp[i][i][1] = {0,-abs(a[i-1])};
}
rep(sz,1,n-1) {
rep(l,1,n-sz) {
int r = l + sz;
int t1 = a[l]-a[l-1]-dp[l+1][r][0].se, t2 = a[r-1]-a[l-1]-dp[l+1][r][1].se;
int t3 = a[r-1]-a[r-2]-dp[l][r-1][1].se, t4 = a[r-1]-a[l-1]-dp[l][r-1][0].se;
dp[l][r][0] = max(make_pair(dp[l+1][r][0].fi + (abs(t1)<=t[l-1]), -t1), make_pair(dp[l+1][r][1].fi + (abs(t2)<=t[l-1]), -t2));
dp[l][r][0] = max(dp[l][r][0], dp[l][r-1][0]);
dp[l][r][1] = max(make_pair(dp[l][r-1][0].fi + (abs(t3)<=t[r-1]), -t3), make_pair(dp[l][r-1][1].fi + (abs(t4)<=t[r-1]), -t4));
dp[l][r][1] = max(dp[l][r][1], dp[l+1][r][1]);
}
}
ans = max(ans,max(dp[1][n][0], dp[1][n][1]).fi);
rep(l,1,n) rep(r,1,n) dp[l][r][0] = dp[l][r][1] = {0, 0};
//rep(i,1,n) cout << a[i-1] << " \n"[i==n];
t.push_front(t.back());
t.pop_back();
a.push_front(a.back()-L);
a.pop_back();
}
cout << ans << '\n';
}
int32_t main() {
setIO();
int tt = 1;
//cin >> tt;
while (tt-- > 0) solve();
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
ho_t3.cpp: In function 'void setIO(std::string)':
ho_t3.cpp:29:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
29 | freopen((name + ".in").c_str(), "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ho_t3.cpp:30:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
30 | freopen((name + ".out").c_str(), "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |