1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Atcoder解いてみた ABC 087 C Candies

Posted at

ABC 087 C Candies

問題はこちら

回答

#include <iostream>
#include <string>
#include <map>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;


int main() {
    // 2xNのマス目 (1<=i<=2, 1<=j<=N)
    int N; // 1<=, <=100
    cin >> N;
    int A[2][100];

    for (int i = 0; i < 2; i++) {
        for (int j = 0; j < N; j++) {
            cin >> A[i][j];
        }
    }

    // 右 or 下しか移動できない
    // どこで下に移動するか?
    // 下移動のパターン:N通り

    // 下移動のパターン:N通り 毎にスコアを求める
    
    int maxSumVal = 0;
    for (int j = 0; j < N; j++) {
        int sumVal = 0;

        // 1行目のスコアの和
        for (int l1 = 0; l1 <= j; l1++) {
            sumVal += A[0][l1];
        }
        // 2行目のスコアの和
        for (int l2 = j; l2 < N; l2++) {
            sumVal += A[1][l2];
        }

        if (maxSumVal <= sumVal) {
            maxSumVal = sumVal;
        }
    }

    std::cout << maxSumVal << std::endl;

    return 0;
}

DPによる解法も要参考

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?