Universal Cup Judging System

Universal Cup

Süre Sınırı: 3.0 s Bellek Sınırı: 1024 MB Toplam puan: 100 Hack'lenebilir ✓
İstatistikler

음이 아닌 정수 쌍 $W, S$가 주어집니다.

퍼핀 Pataro는 혼자서 카드 게임을 하고 있습니다. 카드에는 카드 w와 카드 s의 두 종류가 있습니다.

처음에 Pataro는 w 종류의 카드 $W$장과 s 종류의 카드 $S$장을 가지고 있으며, 점수는 $0$입니다. 그는 모든 카드를 소모할 때까지 가지고 있는 카드 중 한 장을 반복해서 소모합니다. $i$번째로 소모한 카드가 카드 s일 때 다음과 같은 효과가 발생합니다:

  • $(i - 1)$번째, $(i - 2)$번째, $(i - 3)$번째로 소모한 카드 중 카드 w의 개수를 $x$라 합시다. 그는 $27 \times \left(\frac{4}{3}\right)^x$의 점수를 얻습니다.

편의를 위해, $0$번째 또는 그 이전 위치에서 소모된 카드는 카드 w가 아니라고 가정합니다.

Pataro가 적절한 순서로 카드를 소모하여 얻을 수 있는 최대 총점을 구하세요. 구하고자 하는 답은 항상 정수임을 증명할 수 있습니다.

$T$개의 테스트 케이스에 대해 위 문제를 해결하세요.

입력

입력은 다음 형식으로 주어집니다:

T
case1
case2
:
caseT

각 테스트 케이스는 다음 형식으로 주어집니다:

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$번째로 소모된 카드 중 w 종류의 카드는 $2$장이므로, 그는 $27 \times \left(\frac{4}{3}\right)^2 = 48$점을 얻습니다.
  • $4$번째로 소모된 카드는 카드 s입니다. $3$번째, $2$번째, $1$번째로 소모된 카드 중 w 종류의 카드는 $2$장이므로, 그는 $27 \times \left(\frac{4}{3}\right)^2 = 48$점을 얻습니다.
  • $8$번째로 소모된 카드는 카드 s입니다. $7$번째, $6$번째, $5$번째로 소모된 카드 중 w 종류의 카드는 $3$장이므로, 그는 $27 \times \left(\frac{4}{3}\right)^3 = 64$점을 얻습니다.

따라서 Pataro가 얻을 수 있는 총점은 $160$입니다. 카드를 어떻게 소모하더라도 $160$보다 큰 점수를 얻는 것은 불가능하므로 답은 $160$입니다.

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
#1484EditorialOpen题解jianglyView
#1342EditorialOpen题解MilmonView

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.