QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#372465 | #3032. Cheese Game | SolitaryDream# | AC ✓ | 102ms | 9872kb | C++17 | 799b | 2024-03-31 13:51:15 | 2024-03-31 13:51:15 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 1e6 + 10;
int a[N], f[N];
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
int Case;
cin >> Case;
while (Case--) {
int n;
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
}
f[0] = 0;
f[1] = a[1];
f[2] = max(a[1], a[2]);
if (n <= 2) {
cout << f[n] << endl;
continue;
}
for (int i = 3; i <= n; ++i) {
f[i] = f[i - 2] + a[i];
f[i] = max(f[i], f[i - 3] + a[i] + min(a[i - 1], a[i - 2]));
}
int ans = max({f[n], f[n - 1], f[n - 2] + min(a[n], a[n - 1])});
cout << ans << endl;
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 5656kb
input:
20 2 2 1 1 1000000 4 3 2 4 3 8 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 8 1000000 1000000 1000000 1 1000000 1000000 1000000 1000000 9 723059 133070 898168 961394 18457 175012 478043 176230 377374 8 289384 930887 692778 636916 747794 238336 885387 760493 8 516650 641422 202363 ...
output:
2 1000000 8 5000000 5000000 2691397 3314426 2475496 4999998 10 3 1 2 8 4000001 15 3213803 24 3000002 4
result:
ok 20 lines
Test #2:
score: 0
Accepted
time: 102ms
memory: 9872kb
input:
20 100000 859485 390674 819590 695284 505824 962572 577989 53378 307332 754253 103728 302519 19948 48169 659522 389802 262161 848413 224854 965949 70782 789156 772974 876205 410327 900390 392837 362222 582187 762071 74734 958024 152744 410676 169659 174919 373247 264000 744649 196931 18252 848376 15...
output:
33024883937 33135467117 66667000000 33237375393 58332975002 33104918259 33172888838 33156623430 33090460100 33042109608 32999667097 33111199056 3333366667 32982135568 33144273501 56831006063 33108905993 33124668910 33126313979 33069028435
result:
ok 20 lines