# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1264736 | wedonttalkanymore | Collecting Stamps 3 (JOI20_ho_t3) | C++20 | 0 ms | 320 KiB |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define int long long
#define pii pair<ll, ll>
#define fi first
#define se second
const ll N = 200 + 5, inf = 1e18, mod = 1e9 + 7, block = 320, lim = 16;
int n, L;
int a[N], a1[N];
int t[N], t1[N];
int pfs[N], pfs1[N];
int dp[N][N];
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
if (fopen(".inp", "r")) {
freopen(".inp", "r", stdin);
freopen(".out", "w", stdout);
}
cin >> n >> L;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 1; i <= n; i++) a1[i] = L - a[i];
for (int i = 1; i <= n; i++) cin >> t[i];
for (int i = 1; i <= n; i++) t1[i] = L - t[i];
for (int i = 1; i <= n; i++) pfs[i] = pfs[i - 1] + a[i] - a[i - 1]; // xuoi kim dong ho
for (int i = 1; i <= n; i++) pfs1[i] = pfs1[i - 1] + a1[i] - a1[i - 1]; // nguoc
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= n; j++) {
dp[i][j] = -inf;
}
}
dp[0][0] = 0;
for (int i = 1; i <= n; i++) {
dp[0][i] = dp[0][i - 1]; // xuoi
dp[i][0] = dp[i - 1][0]; // nguoc
if (pfs[i] <= t[i]) {
dp[0][i]++;
}
if (pfs1[i] <= t1[i]) {
dp[i][0]++;
}
}
int ans = 0;
for (int i = 0; i < n; i++) { // nguoc
for (int j = 0; j < n - i + 1; j++) { // xuoi
if (pfs[j + 1] + pfs1[i] <= t[j + 1]) {
dp[i][j + 1] = max(dp[i][j + 1], dp[i][j] + 1);
ans = max(ans, dp[i][j + 1]);
}
if (pfs[j] + pfs1[i + 1] <= t1[i + 1]) {
dp[i + 1][j] = max(dp[i + 1][j], dp[i][j] + 1);
ans = max(ans, dp[i + 1][j]);
}
}
}
cout << ans;
return 0;
}
Compilation message (stderr)
# | 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... |