結果

問題 No.1715 Dinner 2
コンテスト
ユーザー ks2m
提出日時 2021-10-22 21:55:27
言語 Java
(openjdk 26.0.2.1 + ACL)
コンパイル:
javac -J-Duser.language=en -encoding UTF8 -cp /opt/aclib/ac_library.jar _filename_
実行:
java -ea -Xmx700m -Xss256M -DONLINE_JUDGE=true -cp .:/opt/aclib/ac_library.jar _class_
結果
WA  
実行時間 -
コード長 1,052 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,529 ms
コンパイル使用メモリ 83,672 KB
実行使用メモリ 43,612 KB
最終ジャッジ日時 2026-09-02 23:48:04
合計ジャッジ時間 5,228 ms
ジャッジサーバーID
(参考情報)
judge2_1 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 34 WA * 4
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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);
	}
}
0