CF1400B RPG Protagonist

题目描述

有两个人去买武器,两个人的最大承重分别为 $a,b$,武器店有剑和战斧,有 $c_1$ 把剑,每一把剑的重量为 $w_1$,有 $c_2$ 把战斧,每一把战斧的重量为 $w_2$。两个人购买的武器总重量不能超过自生的最大承重,两个人购买的剑的总数不能超过 $c_1$,购买战斧的总数不能超过 $c_2$,求在满足条件下两人能买到的武器总数的最大值。 本题多测,$1\leqslant a,b,w_1,w_2\leqslant10^9,1\leqslant c_1,c_2\leqslant 2\times 10^5,1\leqslant \sum c_1,\sum c_2\leqslant 2\times 10^5$。

输入格式

第一行一个正整数 $T\ (1\leqslant T\leqslant10^4)$ 表示数据组数。

输出格式

对于每组数据,输出一行一个整数,表示两个人最多能买到的武器数量。

说明/提示

In the first test case: - you should take $ 3 $ swords and $ 3 $ war axes: $ 3 \cdot 5 + 3 \cdot 6 = 33 \le 33 $ - and your follower — $ 3 $ swords and $ 2 $ war axes: $ 3 \cdot 5 + 2 \cdot 6 = 27 \le 27 $ . $ 3 + 3 + 3 + 2 = 11 $ weapons in total. In the second test case, you can take all available weapons even without your follower's help, since $ 5 \cdot 10 + 5 \cdot 10 \le 100 $ . In the third test case, you can't take anything, but your follower can take $ 3 $ war axes: $ 3 \cdot 5 \le 19 $ .