QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#867765 | #2726. Fun Palace | hhoppitree | 25 ✓ | 26ms | 82464kb | C++17 | 1.0kb | 2025-01-23 23:32:01 | 2025-01-23 23:32:03 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 1005;
int f[N][20005], a[N], b[N];
signed main() {
int n, m; scanf("%d%d", &n, &m);
for (int i = 1; i < n; ++i) {
scanf("%d%d", &a[i], &b[i]);
}
memset(f, -0x3f, sizeof(f));
for (int i = 0; i < m; ++i) f[1][i] = i;
for (int i = 1; i < n; ++i) {
int tmp = -2e9;
for (int j = 0; j <= 20000; ++j) {
if (f[i][j] < 0) continue;
if (j < a[i]) {
tmp = max(tmp, f[i][j]);
f[i + 1][j + b[i]] = max(f[i + 1][j + b[i]], f[i][j] + b[i]);
} else if (j < a[i] + b[i]) {
f[i + 1][j - a[i]] = max(f[i + 1][j - a[i]], f[i][j]);
} else {
f[i + 1][j] = max(f[i + 1][j], f[i][j]);
}
}
for (int j = 0; j < b[i]; ++j) {
f[i + 1][j] = max(f[i + 1][j], tmp + j);
}
}
printf("%d\n", *max_element(f[n], f[n] + 20000 + 1));
return 0;
}
詳細信息
Subtask #1:
score: 3
Accepted
Test #1:
score: 3
Accepted
time: 4ms
memory: 82440kb
input:
2 1 1 1
output:
1
result:
ok single line: '1'
Test #2:
score: 3
Accepted
time: 1ms
memory: 82356kb
input:
3 1 1 1 1 1
output:
1
result:
ok single line: '1'
Test #3:
score: 3
Accepted
time: 2ms
memory: 82404kb
input:
4 2 1 1 1 1 1 1
output:
2
result:
ok single line: '2'
Test #4:
score: 3
Accepted
time: 2ms
memory: 82464kb
input:
5 2 1 1 1 1 1 1 1 1
output:
3
result:
ok single line: '3'
Test #5:
score: 3
Accepted
time: 4ms
memory: 82452kb
input:
3 4 1 1 1 1
output:
3
result:
ok single line: '3'
Test #6:
score: 3
Accepted
time: 2ms
memory: 82376kb
input:
4 9 1 1 1 1 1 1
output:
8
result:
ok single line: '8'
Subtask #2:
score: 5
Accepted
Test #7:
score: 5
Accepted
time: 0ms
memory: 82188kb
input:
1 1
output:
0
result:
ok single line: '0'
Test #8:
score: 5
Accepted
time: 1ms
memory: 82432kb
input:
1 2
output:
1
result:
ok single line: '1'
Test #9:
score: 5
Accepted
time: 8ms
memory: 82392kb
input:
1000 1 2 1 2 1 1 1 2 2 2 1 1 1 1 1 1 2 1 2 2 1 2 2 2 2 2 2 2 1 2 2 1 2 2 2 2 1 1 2 2 1 2 2 1 2 1 2 2 1 1 1 2 2 2 1 1 2 1 1 1 2 2 2 1 1 1 2 1 1 2 1 1 1 2 2 1 1 2 1 2 2 2 2 1 2 2 2 1 2 2 1 2 1 1 1 1 2 2 1 1 1 1 2 1 1 2 1 2 1 2 2 2 1 2 2 2 1 2 1 1 2 2 2 2 1 1 1 1 1 1 1 1 1 1 1 2 2 1 1 2 2 1 1 1 1 1 2 1...
output:
717
result:
ok single line: '717'
Test #10:
score: 5
Accepted
time: 12ms
memory: 82376kb
input:
981 2 1 2 2 2 1 2 2 2 2 1 1 2 2 2 1 1 1 1 1 2 2 1 2 2 2 2 2 1 1 1 2 1 2 1 2 1 2 2 1 1 1 1 2 2 2 2 2 1 1 1 1 2 1 2 2 2 2 1 1 2 2 2 2 1 2 1 1 1 2 1 2 1 2 2 2 1 2 1 1 2 2 1 1 1 1 1 2 1 2 1 1 1 2 1 1 1 2 2 1 1 1 1 1 2 1 1 1 2 1 1 1 2 1 2 1 1 1 2 2 2 2 2 2 2 2 2 1 1 2 1 2 1 1 2 2 1 1 2 2 1 2 2 1 2 2 1 2 ...
output:
707
result:
ok single line: '707'
Subtask #3:
score: 12
Accepted
Test #11:
score: 12
Accepted
time: 1ms
memory: 82444kb
input:
2 20 5 5
output:
19
result:
ok single line: '19'
Test #12:
score: 12
Accepted
time: 3ms
memory: 82364kb
input:
2 20 5 20
output:
24
result:
ok single line: '24'
Test #13:
score: 12
Accepted
time: 5ms
memory: 82352kb
input:
7 7 2 8 6 6 1 1 2 4 2 8 7 8
output:
23
result:
ok single line: '23'
Test #14:
score: 12
Accepted
time: 5ms
memory: 82372kb
input:
1 122
output:
121
result:
ok single line: '121'
Test #15:
score: 12
Accepted
time: 4ms
memory: 82316kb
input:
1 11
output:
10
result:
ok single line: '10'
Test #16:
score: 12
Accepted
time: 6ms
memory: 82392kb
input:
200 150 132 123 186 124 156 123 166 60 71 79 55 159 40 194 35 18 197 13 130 176 25 106 193 6 19 65 128 190 5 86 4 100 173 185 30 124 103 100 1 114 113 105 120 72 125 178 94 196 74 175 68 95 180 171 70 135 96 175 142 21 177 78 120 48 134 191 156 41 121 119 32 149 57 60 19 78 129 115 123 122 15 34 128...
output:
14013
result:
ok single line: '14013'
Test #17:
score: 12
Accepted
time: 1ms
memory: 82344kb
input:
194 162 191 24 178 21 173 97 57 172 130 163 156 175 23 162 89 3 140 173 16 180 27 104 95 133 155 98 52 193 190 192 198 78 91 184 181 117 180 175 117 124 177 172 160 83 44 58 73 178 115 162 153 50 130 31 157 79 118 48 86 173 106 153 152 64 6 82 3 26 155 199 189 57 112 126 111 22 144 172 123 103 34 80...
output:
14097
result:
ok single line: '14097'
Subtask #4:
score: 5
Accepted
Dependency #1:
100%
Accepted
Dependency #2:
100%
Accepted
Dependency #3:
100%
Accepted
Test #18:
score: 5
Accepted
time: 13ms
memory: 82260kb
input:
1000 165 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...
output:
500
result:
ok single line: '500'
Test #19:
score: 5
Accepted
time: 10ms
memory: 82336kb
input:
981 158 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
output:
491
result:
ok single line: '491'
Test #20:
score: 5
Accepted
time: 2ms
memory: 82324kb
input:
1 8655
output:
8654
result:
ok single line: '8654'
Test #21:
score: 5
Accepted
time: 25ms
memory: 82304kb
input:
1000 3898 285 1505 4440 5701 3635 4207 825 1338 7519 7719 346 2400 7763 8911 9454 9169 119 357 8479 5754 6743 4185 9850 1214 4336 526 8144 2660 5223 3452 2999 8133 6978 1185 1255 1695 8940 2107 4094 2628 7797 959 7212 2059 9136 9014 2312 4958 2692 6923 6057 11 9372 110 4061 660 1047 8084 1445 4526 3...
output:
3503312
result:
ok single line: '3503312'
Test #22:
score: 5
Accepted
time: 26ms
memory: 82364kb
input:
1000 4618 1834 6250 6621 4954 2412 8894 2109 8198 4405 862 7385 9786 1492 1938 7371 9595 1870 1079 5424 9503 4520 8990 4233 7775 9952 4747 301 4268 8197 5382 3270 424 3114 3294 8559 3320 6311 9345 13 2921 5912 9444 1667 6056 220 8529 3852 168 8455 2740 5109 10000 896 302 1295 9547 7668 8131 9250 674...
output:
3505300
result:
ok single line: '3505300'
Test #23:
score: 5
Accepted
time: 24ms
memory: 82428kb
input:
974 160 6918 8267 8409 6670 4136 345 3898 1898 8113 2797 6384 1731 255 6498 3762 6476 8903 9362 8943 267 7919 7936 1560 2474 4437 3072 35 2090 6886 362 2122 1723 7800 5514 4090 1525 7937 4979 2933 1427 9421 5319 4032 5379 2796 5616 8453 5959 7873 299 1058 3766 1860 9656 8857 347 4177 4363 9902 3525 ...
output:
3413376
result:
ok single line: '3413376'
Test #24:
score: 5
Accepted
time: 19ms
memory: 82448kb
input:
691 9004 7472 1937 7662 8150 8824 1629 8054 3376 8552 9837 9178 3972 578 4415 4188 4034 6921 6307 5395 3852 8533 5023 5417 2683 8658 637 155 1960 6112 6440 1709 5156 9908 3218 6116 5792 5174 8193 1737 9542 7906 9774 4925 6462 2311 7156 9071 1721 9498 9351 4152 1099 4756 6890 448 6968 6928 4872 6309 ...
output:
2426822
result:
ok single line: '2426822'
Extra Test:
score: 0
Extra Test Passed