結果

問題 No.968 引き算をして門松列(その3)
ユーザー ks2mks2m
提出日時 2020-01-13 21:51:13
言語 Java
(openjdk 23)
結果
AC  
実行時間 299 ms / 2,000 ms
コード長 1,834 bytes
コンパイル時間 2,362 ms
コンパイル使用メモリ 77,760 KB
実行使用メモリ 45,268 KB
最終ジャッジ日時 2024-12-23 00:23:23
合計ジャッジ時間 5,822 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 10
権限があれば一括ダウンロードができます

ソースコード

diff #

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 t = Integer.parseInt(br.readLine());
		for (int i = 0; i < t; i++) {
			String[] sa = br.readLine().split(" ");
			long a = Integer.parseInt(sa[0]);
			long b = Integer.parseInt(sa[1]);
			long c = Integer.parseInt(sa[2]);
			long x = Integer.parseInt(sa[3]);
			long y = Integer.parseInt(sa[4]);
			long z = Integer.parseInt(sa[5]);

			long ans = Long.MAX_VALUE;
			long[] v = new long[3];
			v[0] = b;
			v[1] = a;
			v[2] = c;
			long c1 = Math.max(Math.max(v[1] + 1, v[2] + 2) - v[0], 0);
			long c2 = Math.max(v[2] + 1 - v[1], 0);
			if (v[0] >= c2 + 3 && v[1] >= c1 + 2 && v[2] >= c1 + c2 + 1) {
				long val = c1 * z + c2 * y;
				ans = Math.min(ans, val);
			}

			v[0] = b;
			v[1] = c;
			v[2] = a;
			c1 = Math.max(Math.max(v[1] + 1, v[2] + 2) - v[0], 0);
			c2 = Math.max(v[2] + 1 - v[1], 0);
			if (v[0] >= c2 + 3 && v[1] >= c1 + 2 && v[2] >= c1 + c2 + 1) {
				long val = c1 * z + c2 * x;
				ans = Math.min(ans, val);
			}

			v[0] = a;
			v[1] = c;
			v[2] = b;
			c1 = Math.max(Math.max(v[1] + 1, v[2] + 2) - v[0], 0);
			c2 = Math.max(v[2] + 1 - v[1], 0);
			if (v[0] >= c2 + 3 && v[1] >= c1 + 2 && v[2] >= c1 + c2 + 1) {
				long val = c1 * y + c2 * x;
				ans = Math.min(ans, val);
			}

			v[0] = c;
			v[1] = a;
			v[2] = b;
			c1 = Math.max(Math.max(v[1] + 1, v[2] + 2) - v[0], 0);
			c2 = Math.max(v[2] + 1 - v[1], 0);
			if (v[0] >= c2 + 3 && v[1] >= c1 + 2 && v[2] >= c1 + c2 + 1) {
				long val = c1 * x + c2 * y;
				ans = Math.min(ans, val);
			}

			if (ans == Long.MAX_VALUE) {
				System.out.println(-1);
			} else {
				System.out.println(ans);
			}
		}
		br.close();
	}
}
0