QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#555641 | #8586. Party | Jioru | 0 | 0ms | 3728kb | C++20 | 653b | 2024-09-10 07:18:48 | 2024-09-10 07:18:48 |
answer
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
if (n == 0) {
cout << 0 << endl;
return 0;
}
if (n == 1) {
cout << max(0, a[0]) << endl;
return 0;
}
vector<int> dp(n);
dp[0] = max(0, a[0]);
dp[1] = max(dp[0], a[1]);
for (int i = 2; i < n; ++i) {
dp[i] = max(dp[i-1], a[i] + dp[i-2]);
}
//for god's sike work
cout << dp[n-1] << endl;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3728kb
input:
5 3 2 -1 4 5
output:
8
result:
wrong answer 1st lines differ - expected: '12', found: '8'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Skipped
Dependency #1:
0%