結果
問題 |
No.1433 Two color sequence
|
ユーザー |
![]() |
提出日時 | 2021-03-19 21:52:15 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 348 ms / 2,000 ms |
コード長 | 757 bytes |
コンパイル時間 | 2,370 ms |
コンパイル使用メモリ | 76,300 KB |
実行使用メモリ | 60,684 KB |
最終ジャッジ日時 | 2024-11-18 22:00:36 |
合計ジャッジ時間 | 10,778 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 21 |
ソースコード
import java.io.BufferedReader; import java.io.InputStreamReader; public class Main { public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(br.readLine()); char[] s = br.readLine().toCharArray(); String[] sa = br.readLine().split(" "); int[] a = new int[n]; for (int i = 0; i < n; i++) { a[i] = Integer.parseInt(sa[i]); } br.close(); long max = 0; long min = 0; long[] b = new long[n + 1]; for (int i = 0; i < n; i++) { if (s[i] == 'R') { b[i + 1] = b[i] + a[i]; } else { b[i + 1] = b[i] - a[i]; } max = Math.max(max, b[i + 1]); min = Math.min(min, b[i + 1]); } System.out.println(max - min); } }