結果
問題 | No.2812 Plus Minus Blackboard |
ユーザー | ks2m |
提出日時 | 2024-07-19 21:34:11 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 580 ms / 2,000 ms |
コード長 | 1,064 bytes |
コンパイル時間 | 2,375 ms |
コンパイル使用メモリ | 79,096 KB |
実行使用メモリ | 71,476 KB |
最終ジャッジ日時 | 2024-07-21 20:26:29 |
合計ジャッジ時間 | 11,265 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 22 |
ソースコード
import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Collections; import java.util.List; 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()); 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(); List<Integer> lm = new ArrayList<>(); List<Integer> lp = new ArrayList<>(); long sum = 0; for (int i = 0; i < n; i++) { if (a[i] < 0) { lm.add(-a[i]); } else { lp.add(a[i]); } sum += a[i]; } Collections.sort(lm); Collections.sort(lp); if (sum < 0) { sum += lm.get(lm.size() - 1); if (sum >= 0) { System.out.println("Yes"); } else { System.out.println("No"); } } else { sum -= lp.get(lp.size() - 1); if (sum <= 0) { System.out.println("Yes"); } else { System.out.println("No"); } } } }