結果
問題 | No.2309 [Cherry 5th Tune D] 夏の先取り |
ユーザー |
|
提出日時 | 2023-05-19 23:52:38 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 44 ms / 3,000 ms |
コード長 | 1,637 bytes |
コンパイル時間 | 755 ms |
コンパイル使用メモリ | 77,456 KB |
最終ジャッジ日時 | 2025-02-13 03:28:11 |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 50 |
ソースコード
#include<iostream>#include<vector>#include<algorithm>#include<map>using namespace std;using ll=long long;#define rep(i,n) for(int i=0;i<n;i++)#define rrep(i,n) for(int i=(n)-1;i>=0;i--)#define all(v) v.begin(),v.end()#define rall(v) v.rbegin(),v.rend()template<class T> bool chmax(T &a, T b){if (a < b){a = b;return true;} else return false;}template<class T> bool chmin(T &a, T b){if (a > b){a = b;return true;} else return false;}ll X,Y,Z,W;ll f1(int p,int a,int b,int c){if(p<0||p>a||min(b-p,c-a+p)<0)return 0;return X*p+Y*min(b-p,c-a+p)+Z*(a-p);}ll f2(int p,int a,int b,int c){if(p<0||p>b||min(c-p,a-b+p)<0)return 0;return X*(b-p)+Y*p+Z*min(c-p,a-b+p);}ll f3(int p,int a,int b,int c){if(p<0||p>c||min(a-p,b-c+p)<0)return 0;return X*min(a-p,b-c+p)+Y*(c-p)+Z*p;}void solve(){int A,B,C;cin>>A>>B>>C;cin>>X>>Y>>Z>>W;ll ans=0;for(int i=0;i<=min(A,min(B,C));i++){ll cnt=W*i;ll a=A-i,b=B-i,c=C-i;chmax(ans,cnt+f1(0,a,b,c));chmax(ans,cnt+f1((a+b-c)/2,a,b,c));chmax(ans,cnt+f1((a+b-c+1)/2,a,b,c));chmax(ans,cnt+f1(a,a,b,c));chmax(ans,cnt+f2(0,a,b,c));chmax(ans,cnt+f2((b+c-a)/2,a,b,c));chmax(ans,cnt+f2((b+c-a+1)/2,a,b,c));chmax(ans,cnt+f2(b,a,b,c));chmax(ans,cnt+f3(0,a,b,c));chmax(ans,cnt+f3((c+a-b)/2,a,b,c));chmax(ans,cnt+f3((c+a-b+1)/2,a,b,c));chmax(ans,cnt+f3(c,a,b,c));}cout<<ans<<"\n";}int main(){ios::sync_with_stdio(false);cin.tie(nullptr);int T;cin>>T;while(T--){solve();}}