做这个题的时候我一直在想同一个节目的不同期是否能够同时录制,然后就看到那句话
在节目都连续录制的假设下,就把这句话理解成了同一个节目必须连续录制,而不能同时
录制,然后就一直思考同一个节目不同时录制的情况下的最优解,就死在了这个问题上。
后来看了题解竟然发现可以同时录制。然后这题就是枚举y,然后贪心,用z去弥补差值,
然后比较每次解的大小,取最小。
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<cstdlib>
using namespace std;
#define LL long long
#define For(i,n) for(int i=1;i<=n;i++)
#define Rep(i,n) for(int i=0;i<n;i++)
int main()
{
int cas;
cin>>cas;
LL e[10],t[10];
while(cas--)
{
For(i,4) cin>>e[i];
For(i,4) cin>>t[i];
if(t[3]<t[4])
{
swap(t[3],t[4]),
swap(e[3],e[4]);
}
LL Ans=1LL<<60;
// cout<<Ans<<endl;
Rep(i,e[3]+1)
{
LL ans;
LL t1=e[1]*t[1]+i*t[3],t2=e[2]*t[2]+(e[3]-i)*t[3];
if(t1>t2)
swap(t1,t2);
LL m=(t2-t1)/t[4];
if(e[4]<=m)
ans=t2;
else
{
t1=t1+m*t[4];
LL cn=e[4]-m;
if(cn%2==1)
ans=t1+(cn/2+1)*t[4];
else
ans=t2+(cn/2)*t[4];
}
Ans=min(ans,Ans);
}
cout<<Ans<<endl;
}
return 0;
}