QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#208994 | #7567. Joining Cats | lanhf | WA | 8ms | 101468kb | C++17 | 1.1kb | 2023-10-09 23:40:26 | 2023-10-09 23:40:26 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 5005;
int n, k, dp[N][N], a[N];
long long sum[N], can[N];
int main() {
cin.tie(0)->sync_with_stdio(0);
cin >> n >> k;
for (int i = 1; i <= n; i++) {
cin >> a[i]; sum[i] = sum[i - 1] + a[i];
}
for (int i = 1; i <= k; i++)
cin >> can[i];
memset(dp, 0x3f, sizeof dp);
a[0] = a[n + 1] = dp[0][0];
for (int i = n; i > 0; i--) {
dp[i][i] = 0;
for (int j = i; j <= n; j++) {
int v = dp[i][j] + 1;
while (v <= k && can[v] < min(a[i - 1], a[j + 1])) v++;
if (v > k) break;
int l = 0, r = i - 1;
while (l < r) {
int m = (l + r) / 2;
if (sum[i - 1] - sum[m] <= can[v])
r = m;
else l = m + 1;
}
dp[r + 1][j] = min(dp[r + 1][j], v);
l = j; r = n;
while (l < r) {
int m = (l + r + 1) / 2;
if (sum[m] - sum[j] <= can[v])
l = m;
else r = m - 1;
}
dp[i][l] = min(dp[i][l], v);
}
}
cout << (dp[1][n] <= k ? "Yes" : "No");
}
詳細信息
Test #1:
score: 100
Accepted
time: 8ms
memory: 101208kb
input:
5 2 1 1 1 1 1 2 2
output:
Yes
result:
ok answer is YES
Test #2:
score: 0
Accepted
time: 0ms
memory: 101268kb
input:
6 7 3 2 1 1 2 3 2 2 2 2 2 2 2
output:
No
result:
ok answer is NO
Test #3:
score: -100
Wrong Answer
time: 3ms
memory: 101468kb
input:
7 4 1 2 3 4 3 2 1 3 3 3 3
output:
No
result:
wrong answer expected YES, found NO