結果
| 問題 | No.1433 Two color sequence | 
| コンテスト | |
| ユーザー |  se1ka2 | 
| 提出日時 | 2021-03-19 21:52:09 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 92 ms / 2,000 ms | 
| コード長 | 516 bytes | 
| コンパイル時間 | 536 ms | 
| コンパイル使用メモリ | 66,056 KB | 
| 実行使用メモリ | 5,376 KB | 
| 最終ジャッジ日時 | 2024-11-18 22:00:01 | 
| 合計ジャッジ時間 | 3,213 ms | 
| ジャッジサーバーID (参考情報) | judge2 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 21 | 
ソースコード
#include <iostream>
using namespace std;
typedef long long ll;
int main()
{
    int n;
    string s;
    cin >> n >> s;
    ll a[200005];
    for(int i = 0; i < n; i++) cin >> a[i];
    ll r = 0, b = 0, ans = 0;
    for(int i = 0; i < n; i++){
        if(s[i] == 'R'){
            r = max(0ll, r + a[i]);
            b = max(0ll, b - a[i]);
        }
        else{
            r = max(0ll, r - a[i]);
            b = max(0ll, b + a[i]);
        }
        ans = max(ans, max(r, b));
    }
    cout << ans << endl;
}
            
            
            
        