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?

More than 3 years have passed since last update.

[AtCoder] ABC 189 C - Mandarin Orange

Posted at

解説と解法が同じでガッツポーズ。
$l$を固定して$r$を移動させながら最大値を探します。
$l$から$r$の間の最小値$A_{i}$を求めながら、それまでのみかんの最大値と比較して更新していきます。
計算量は$O(N^2)$ですが、$1 \le N \le 10^4$なのでいけると判断しました。
言語はC++(GCC 9.2.1)でAtCoderのコードテストで確認しています。

#include <bits/stdc++.h>
using namespace std;

int main() {
  int N;
  long long maxA, result = 0;
  cin >> N;
  
  vector<int> A(N);
  
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  
  for (int i = 0; i < N; i++) {
    maxA = A[i];
    for (int j = i; j < N; j++) {
      if (A[j] < maxA) {
        maxA = A[j];
      }
      result = max(result, (j - i + 1) * maxA);
    }
  }
  
  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?