結果

問題 No.561 東京と京都
コンテスト
ユーザー hhgfhn1
提出日時 2018-10-29 21:06:29
言語 Java
(openjdk 27 + 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_
結果
TLE  
実行時間 -
コード長 714 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,452 ms
コンパイル使用メモリ 85,564 KB
実行使用メモリ 46,260 KB
最終ジャッジ日時 2026-09-26 14:23:04
合計ジャッジ時間 8,317 ms
ジャッジサーバーID
(参考情報)
judge2_1 / judge4_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 7 TLE * 1 -- * 9
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import java.util.Scanner;

public class Main {

	@SuppressWarnings("resource")
	public static void main(String args[]) {
		Scanner scanner = new Scanner(System.in);
		int n=scanner.nextInt();
		int d=scanner.nextInt();
		t=new int[n];
		k=new int[n];
		for(int i=0;i<n;i++) {
			t[i]=scanner.nextInt();
			k[i]=scanner.nextInt();
		}
		dfs(0,0,true,d,n);
		System.out.println(max);
	}

	static int t[];
	static int k[];
	static int max=0;
	private static void dfs(int i, int c, boolean is_t, int d, int n) {
		if(i==n) {
			max=Math.max(max, c);
			return;
		}
		if(is_t) {
			dfs(i+1,c+t[i],true,d,n);
			dfs(i+1,c+k[i]-d,false,d,n);
		}else {
			dfs(i+1,c+t[i]-d,true,d,n);
			dfs(i+1,c+k[i],false,d,n);
		}
	}
}
0