結果

問題 No.968 引き算をして門松列(その3)
ユーザー ぷらぷら
提出日時 2021-03-14 03:13:14
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 34 ms / 2,000 ms
コード長 916 bytes
コンパイル時間 1,514 ms
コンパイル使用メモリ 165,144 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-23 14:42:42
合計ジャッジ時間 2,242 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 11 ms
6,944 KB
testcase_04 AC 11 ms
6,944 KB
testcase_05 AC 11 ms
6,944 KB
testcase_06 AC 12 ms
6,940 KB
testcase_07 AC 15 ms
6,940 KB
testcase_08 AC 27 ms
6,944 KB
testcase_09 AC 31 ms
6,940 KB
testcase_10 AC 34 ms
6,944 KB
testcase_11 AC 34 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

long long solve(long long A,long long B,long long C,long long Y,long long Z) {
    long long tmp = 0;
    tmp += max(0LL,C-B+1)*Z;
    A -= max(0LL,C-B+1);
    C -= max(0LL,C-B+1);
    tmp += max(0LL,B-A+1)*Y;
    C -= max(0LL,B-A+1);
    B -= max(0LL,B-A+1);
    if(A <= 0 || B <= 0 || C <= 0) {
        return 1e18;
    }
    return tmp;
}

int main() {
    int T;
    cin >> T;
    while (T--) {
        long long A,B,C,X,Y,Z;
        cin >> A >> B >> C >> X >> Y >> Z;
        long long ans = 1e18;
        // 2 1 3
        ans = min(ans,solve(B,A,C,Z,Y));
        // 3 1 2
        ans = min(ans,solve(B,C,A,Z,X));
        // 2 3 1
        ans = min(ans,solve(C,A,B,X,Y));
        // 1 3 2
        ans = min(ans,solve(A,C,B,Y,X));
        if(ans == 1e18) {
            cout << -1 << endl;
        }
        else {
            cout << ans << endl;
        }
    }
}
0