結果
| 問題 |
No.2309 [Cherry 5th Tune D] 夏の先取り
|
| コンテスト | |
| ユーザー |
milanis48663220
|
| 提出日時 | 2023-05-19 23:08:06 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 275 ms / 3,000 ms |
| コード長 | 2,837 bytes |
| コンパイル時間 | 1,035 ms |
| コンパイル使用メモリ | 117,400 KB |
| 最終ジャッジ日時 | 2025-02-13 03:06:44 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 50 |
ソースコード
#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();
}
milanis48663220