結果

問題 No.1433 Two color sequence
ユーザー bonKotsu
提出日時 2021-05-05 00:15:39
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 97 ms / 2,000 ms
コード長 612 bytes
コンパイル時間 1,805 ms
コンパイル使用メモリ 170,640 KB
実行使用メモリ 9,984 KB
最終ジャッジ日時 2024-07-23 19:08:48
合計ジャッジ時間 5,904 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define P pair<int, int>

const ll INF = 1e18;
int main() {
  int n;
  string s;
  cin >> n >> s;
  vector<ll> x(n), sum(n+1), mx(n+1), mn(n+1);
  rep(i, n) {
    cin >> x[i];
    if (s[i] == 'B') x[i] *= -1;
  }
  rep(i, n) sum[i+1] = sum[i] + x[i];
  rep(i, n) {
    mx[i+1] = max(mx[i], sum[i+1]);
    mn[i+1] = min(mn[i], sum[i+1]);
  }
  ll ans = -1e18;
  for (int i = 1; i <= n; i++) {
    ans = max(ans, sum[i]-mn[i]);
    ans = max(ans, abs(sum[i]-mx[i]));
  }
  cout << ans << endl;



}
0