結果
問題 |
No.1715 Dinner 2
|
ユーザー |
![]() |
提出日時 | 2021-10-22 21:55:27 |
言語 | Java (openjdk 23) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,052 bytes |
コンパイル時間 | 2,286 ms |
コンパイル使用メモリ | 77,988 KB |
実行使用メモリ | 51,660 KB |
最終ジャッジ日時 | 2024-09-23 05:22:01 |
合計ジャッジ時間 | 5,903 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 34 WA * 4 |
ソースコード
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)); String[] sa = br.readLine().split(" "); int n = Integer.parseInt(sa[0]); int d = Integer.parseInt(sa[1]); int[] p = new int[n]; int[] q = new int[n]; for (int i = 0; i < n; i++) { sa = br.readLine().split(" "); p[i] = -Integer.parseInt(sa[0]); q[i] = Integer.parseInt(sa[1]); } br.close(); int d1 = (d - 1) / 2; int d2 = d % 2; int ans = Integer.MIN_VALUE; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (i == j) { continue; } int m1 = p[i]; int m2 = m1 + q[i] + p[j]; int sum = m2 + q[j]; if (sum >= 0) { ans = Math.max(ans, Math.min(m1, m2)); } else { if (d2 == 0) { ans = Math.max(ans, sum * d1 + Math.min(m1, m2)); } else { ans = Math.max(ans, sum * d1 + m1); } } } } System.out.println(ans); } }