爱奇艺的自制节目
https://nanti.jisuanke.com/t/A1011
思路:把w,x安排好,枚举y到A房的数量,再贪心选择z;
#include<algorithm>
#include<set>
#include<vector>
#include<queue>
#include<cmath>
#include<cstring>
#include<iostream>
#include<set>
#include<vector>
#include<queue>
#include<cmath>
#include<cstdio>
#include<map>
#include<stack>
#include<string>
using namespace std;
#define sfi(i) scanf("%d",&i)
#define pri(i) printf("%d\n",i)
#define sff(i) scanf("%lf",&i)
#define ll long long
#define mem(x,y) memset(x,y,sizeof(x))
#define INF 0x3f3f3f3f
#define eps 1e-6
#define PI acos(-1)
#define lowbit(x) ((x)&(-x))
#define zero(x) (((x)>0?(x):-(x))<eps)
#define fl() printf("flag\n")
#define MOD(x) ((x%mod)+mod)%mod
#define FASTIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
ll gcd(ll a,ll b){while(b^=a^=b^=a%=b);return a;}
const int maxn=1e5+9;
const int mod=1e9+7;
template <class T>
inline void sc(T &ret)
{
char c;
ret = 0;
while ((c = getchar()) < '0' || c > '9');
while (c >= '0' && c <= '9')
{
ret = ret * 10 + (c - '0'), c = getchar();
}
}
int main()
{
int t;
cin>>t;
while(t--)
{
ll ans=1e18;
ll ew,ex,ey,ez,z,x,w,y,sum1=0,sum2=0;
cin>>ew>>ex>>ey>>ez>>w>>x>>y>>z;
sum1=ew*w;
sum2=ex*x;
for(int i=0;i<=ey;i++)
{
ll res=0;
ll tol=sum1+i*y;
ll toll=sum2+(ey-i)*y;
if(tol>toll) swap(tol,toll);
ll cha=toll-tol;
ll a=cha/z;
if(a>=ez)
{
res=toll;
}
else
{
tol=tol+a*z;
ll yu=ez-a;
if(yu%2)
res=tol+(yu/2+1)*z;
else res=toll+yu/2*z;
}
ans=min(ans,res);
}
cout<<ans<<endl;
}
return 0;
}