Universal Cup Judging System

Universal Cup

時間限制: 3.0 s 記憶體限制: 1024 MB 總分: 100 可 Hack ✓
统计

给定一对非负整数 $W, S$。

Puffin Pataro 正在独自玩一个纸牌游戏。有两种类型的牌:牌 w 和牌 s。

最初,Pataro 有 $W$ 张 w 类牌和 $S$ 张 s 类牌,他的分数为 0。他反复从手中的牌中消耗一张,直到所有牌都被消耗完。当第 $i$ 张被消耗的牌是 s 类牌时,会产生以下效果:

  • 在第 $(i-1)$ 张、第 $(i-2)$ 张和第 $(i-3)$ 张被消耗的牌中,设 $x$ 为其中 w 类牌的数量。他获得 $27 \times \left(\frac{4}{3}\right)^x$ 的分数。

为方便起见,假设在位置 0 或更早位置消耗的牌不是 w 类牌。

请找出 Pataro 通过以适当顺序消耗纸牌所能获得的最大总分数。可以证明,所需答案始终是一个整数。

请解决上述 $T$ 组测试用例的问题。

输入格式

输入格式如下:

$T$ $case_1$ $case_2$ $\vdots$ $case_T$

每个测试用例的格式如下:

$W \ S$

  • $1 \le T \le 10^4$
  • $0 \le W, S \le 10^{16}$
  • 所有输入值均为整数。

输出格式

输出 $T$ 行。 第 $i$ 行应包含第 $i$ 组测试用例的答案。

样例

输入 1

3
5 3
12 9
2026 328

输出 1

160
484
20992

说明

在第一个样例中,Pataro 以 w, w, s, s, w, w, w, s 的顺序消耗纸牌是最优的。

  • 第 3 张被消耗的牌是 s 类牌。在第 2 张、第 1 张和第 0 张被消耗的牌中,有 2 张 w 类牌,因此他获得 $27 \times \left(\frac{4}{3}\right)^2 = 48$ 分。
  • 第 4 张被消耗的牌是 s 类牌。在第 3 张、第 2 张和第 1 张被消耗的牌中,有 2 张 w 类牌,因此他获得 $27 \times \left(\frac{4}{3}\right)^2 = 48$ 分。
  • 第 8 张被消耗的牌是 s 类牌。在第 7 张、第 6 张和第 5 张被消耗的牌中,有 3 张 w 类牌,因此他获得 $27 \times \left(\frac{4}{3}\right)^3 = 64$ 分。

因此,Pataro 可以获得的总分是 160。无论如何消耗纸牌,都不可能获得超过 160 的分数,因此答案是 160。

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
#1484EditorialOpen题解jiangly2026-04-09 18:04:11View
#1342EditorialOpen题解Milmon2026-03-29 19:49:45View

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.