結果
問題 |
No.1433 Two color sequence
|
ユーザー |
![]() |
提出日時 | 2021-03-22 12:06:36 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 965 ms / 2,000 ms |
コード長 | 694 bytes |
コンパイル時間 | 2,104 ms |
コンパイル使用メモリ | 74,800 KB |
実行使用メモリ | 57,592 KB |
最終ジャッジ日時 | 2024-11-23 21:49:43 |
合計ジャッジ時間 | 20,295 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 21 |
ソースコード
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); char[] colors = sc.next().toCharArray(); long min = 0; long max = 0; long value = 0; long ans = 0; for (int i = 0; i < n; i++) { int x = sc.nextInt(); if (colors[i] == 'B') { x *= -1; } value += x; ans = Math.max(ans, value - min); ans = Math.max(ans, max - value); min = Math.min(min, value); max = Math.max(max, value); } System.out.println(ans); } }