結果

問題 No.968 引き算をして門松列(その3)
ユーザー ぷら
提出日時 2021-03-14 03:13:14
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 33 ms / 2,000 ms
コード長 916 bytes
コンパイル時間 1,547 ms
コンパイル使用メモリ 167,172 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-10-15 15:02:08
合計ジャッジ時間 2,332 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 10
権限があれば一括ダウンロードができます

ソースコード

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