小木桩之间是相互独立的,即在大木桩之间插入的每一个小木桩对其他小木桩没有影响,因为当有一个小木桩插入完成后,再插入一个新的小木桩不会影响前面的小木桩对答案的贡献。
对于每一个小木桩,设它安插的位置前面有 xxx 个大木桩,则其后有 a−xa - xa−x 个大木桩,则这个小木桩对答案的贡献为 x×(a−x)−xx \times (a - x) - xx×(a−x)−x ,它取最大值的时候 xmax=⌊a2⌋x_{max} =\lfloor \frac{a}{2} \rfloorxmax=⌊2a⌋ ,因此每个小木桩的最大贡献都是 xper=xmax×(a−xmax)−xmaxx_{per}=x_{max}\times(a-x_{max})-x_{max}xper=xmax×(a−xmax)−xmax,因此最大的美观值就是 ans=xper×bans = x_{per}\times bans=xper×b
#include <bits/stdc++.h>
//#define LOCAL
using namespace std;
long long a, b, T;
int main(){
#ifdef LOCAL
freopen("in.in", "r", stdin);
freopen("out.out", "w", stdout);
#endif
ios::sync_with_stdio(0);
while (cin >> T){
while (T--){
cin >> a >> b;
cout << ((a / 2) * (a - (a / 2)) - (a / 2)) * b << "\n";
}
}
return 0;
}