QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#319639#4931. Comic BingefivefiveWA 0ms3640kbC++141.0kb2024-02-02 21:56:282024-02-02 21:56:30

Judging History

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

  • [2024-02-02 21:56:30]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3640kb
  • [2024-02-02 21:56:28]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
#define endl '\n'
#define PB push_back
#define pii pair<int, int>
#define ll long long
using namespace std;
const int N = 2e5 + 5;
const int INF = 1e18;
int a[N], b[N], dp[N][2], dp2[N][2];
void solve(){
    int n;
    cin >> n;
    for(int i=1; i<=n; i++) cin >> a[i];
    for(int i=1; i<=n; i++) cin >> b[i];

    dp[1][0] = INF;
    dp[1][1] = b[1];
    for(int i=2; i<=n; i++){
        dp[i][0] = dp[i-1][1];
        dp[i][1] = min(dp[i-1][0], dp[i-1][1]) + b[i];
    }

    dp2[1][0] = 0;
    dp2[1][1] = a[1] + b[1];
    for(int i=2; i<=n; i++){
        dp2[i][0] = max(dp[i][0], dp2[i-1][1]) + a[i];
        dp2[i][1] = max(dp[i][1], max(dp2[i-1][0], dp2[i-1][1])) + a[i];
        //cout << dp2[i][0] << " " << dp2[i][1] << endl;
    }
    cout << dp2[n][1] << endl;
}
signed main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    int T = 1;
    // cin >> T;
    while(T--){
        solve();
    }

    //testing
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

6
3 1 1 1 1 2
1 5 3 3 7 4

output:

14

result:

wrong answer 1st lines differ - expected: '13', found: '14'