結果

問題 No.2309 [Cherry 5th Tune D] 夏の先取り
ユーザー milanis48663220milanis48663220
提出日時 2023-05-19 23:08:06
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 284 ms / 3,000 ms
コード長 2,837 bytes
コンパイル時間 1,234 ms
コンパイル使用メモリ 119,840 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-23 01:05:41
合計ジャッジ時間 7,719 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 10 ms
4,376 KB
testcase_01 AC 87 ms
4,376 KB
testcase_02 AC 78 ms
4,376 KB
testcase_03 AC 69 ms
4,376 KB
testcase_04 AC 100 ms
4,376 KB
testcase_05 AC 74 ms
4,380 KB
testcase_06 AC 83 ms
4,376 KB
testcase_07 AC 94 ms
4,376 KB
testcase_08 AC 108 ms
4,376 KB
testcase_09 AC 66 ms
4,376 KB
testcase_10 AC 69 ms
4,376 KB
testcase_11 AC 75 ms
4,376 KB
testcase_12 AC 75 ms
4,380 KB
testcase_13 AC 88 ms
4,376 KB
testcase_14 AC 73 ms
4,376 KB
testcase_15 AC 71 ms
4,380 KB
testcase_16 AC 58 ms
4,376 KB
testcase_17 AC 87 ms
4,380 KB
testcase_18 AC 89 ms
4,380 KB
testcase_19 AC 69 ms
4,376 KB
testcase_20 AC 77 ms
4,380 KB
testcase_21 AC 54 ms
4,380 KB
testcase_22 AC 57 ms
4,376 KB
testcase_23 AC 63 ms
4,376 KB
testcase_24 AC 106 ms
4,380 KB
testcase_25 AC 77 ms
4,380 KB
testcase_26 AC 112 ms
4,376 KB
testcase_27 AC 59 ms
4,376 KB
testcase_28 AC 71 ms
4,376 KB
testcase_29 AC 94 ms
4,376 KB
testcase_30 AC 90 ms
4,376 KB
testcase_31 AC 264 ms
4,380 KB
testcase_32 AC 263 ms
4,380 KB
testcase_33 AC 263 ms
4,380 KB
testcase_34 AC 263 ms
4,380 KB
testcase_35 AC 260 ms
4,376 KB
testcase_36 AC 4 ms
4,380 KB
testcase_37 AC 2 ms
4,380 KB
testcase_38 AC 5 ms
4,376 KB
testcase_39 AC 3 ms
4,380 KB
testcase_40 AC 4 ms
4,376 KB
testcase_41 AC 161 ms
4,376 KB
testcase_42 AC 284 ms
4,376 KB
testcase_43 AC 114 ms
4,380 KB
testcase_44 AC 100 ms
4,380 KB
testcase_45 AC 90 ms
4,376 KB
testcase_46 AC 88 ms
4,376 KB
testcase_47 AC 30 ms
4,376 KB
testcase_48 AC 5 ms
4,376 KB
testcase_49 AC 58 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cmath>
#include <numeric>
#include <functional>
#include <cassert>

#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;
#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using namespace std;
typedef long long ll;

template<typename T>
vector<vector<T>> vec2d(int n, int m, T v){
    return vector<vector<T>>(n, vector<T>(m, v));
}

template<typename T>
vector<vector<vector<T>>> vec3d(int n, int m, int k, T v){
    return vector<vector<vector<T>>>(n, vector<vector<T>>(m, vector<T>(k, v)));
}

template<typename T>
void print_vector(vector<T> v, char delimiter=' '){
    if(v.empty()) {
        cout << endl;
        return;
    }
    for(int i = 0; i+1 < v.size(); i++) cout << v[i] << delimiter;
    cout << v.back() << endl;
}

void solve(){
    ll a, b, c; cin >> a >> b >> c;
    ll x, y, z, w; cin >> x >> y >> z >> w;
    vector<ll> price = {y, z, x};
    auto f = [&](ll a, ll b, ll c, int i){
        vector<ll> cnt = {a, b, c};
        // i以外の組が0
        int j = (i+1)%3;
        int k = (i+2)%3;
        if(cnt[i] >= cnt[j]+cnt[k]){
            return price[k]*cnt[j]+price[j]*cnt[k];
        }else{
            if(price[k] > price[j]){
                swap(j, k);
            }
            ll cj = min(cnt[i], cnt[k]);
            ll ck = cnt[i]-cj;
            return cj*price[j]+ck*price[k];
        }
    };
    if(x+y+z >= 2*w){
        ll ans = 0;
        for(ll p = 0; p <= min({1ll, a, b, c}); p++){
            vector<ll> cnt = {a, b, c};
            for(int i = 0; i < 3; i++){
                int j = (i+1)%3;
                int k = (i+2)%3;
                for(ll x = 0; x+p <= min(cnt[j], cnt[k]); x++){
                    ll tmp = p*w + price[i]*x;
                    auto cc = cnt;
                    cc[i] -= p;
                    cc[j] -= x+p;
                    cc[k] -= x+p;
                    tmp += f(cc[0], cc[1], cc[2], i);
                    chmax(ans, tmp);
                }
            }
        }
        cout << ans << endl;
    }else{
        ll ans = 0;
        for(ll p = 0; p <= min({a, b, c}); p++){
            ll tmp = p*w;
            for(int i = 0; i < 3; i++){
                chmax(ans, tmp+f(a-p, b-p, c-p, i));
            }
        }
        cout << ans << endl;
    }
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    int t; cin >> t;
    while(t--) solve();
}
0