QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#556508#8586. Partyallaeben0 0ms3632kbC++14530b2024-09-10 19:03:562024-09-10 19:03:56

Judging History

你现在查看的是最新测评结果

  • [2024-09-10 19:03:56]
  • 评测
  • 测评结果:0
  • 用时:0ms
  • 内存:3632kb
  • [2024-09-10 19:03:56]
  • 提交

answer

#include <iostream>
#include <algorithm>
using namespace std;

int maxHappiness(int n, int a[]) {
    if (n == 0) return 0;
    if (n == 1) return max(0, a[0]);
    int dp[n + 1];
    dp[0] = 0;
    dp[1] = max(0, a[0]);

    for (int i = 2; i <= n; ++i) {
        dp[i] = max(dp[i-1], dp[i-2] + a[i-1]);
    }
    return dp[n];
}
int main() {
    int n;
    cin >> n;
    int a[n];
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }

    cout << maxHappiness(n, a) << endl;

    return 0;
}

詳細信息

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3632kb

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%