0
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 Beginner Contest 134

Last updated at Posted at 2024-09-12

C - Exception Handling

解説

  • 累積maxが使える
    • L: 0からi-1までの累積max
    • R: nからi+1までの累積max
  • ソートする方法もあり?

実装例(C++)

#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];
    }

    vector<int> L_max(n, 0);
    vector<int> R_max(n, 0);

    // L_max[0] = 0
    for (int i = 1; i < n; i++) {
        L_max[i] = max(L_max[i-1], a[i-1]);
    }

    // R_max[n-1] = 0
    for (int i = n-2; i >= 0; i--){
        R_max[i] = max(R_max[i+1], a[i+1]);
    }

    int result = 0;
    for (int d = 0; d < n; d++) {
        result = max(L_max[d], R_max[d]);
        cout << result << endl;
    }
}
0
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
0
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?