Universal Cup Judging System

Universal Cup

시간 제한: 3.0 s 메모리 제한: 1024 MB 총점: 100 해킹 가능 ✓
통계

Panda는 게임을 플레이하고 있으며, $1$번부터 $n$번까지 번호가 매겨진 $n$명의 캐릭터로 이루어진 파티를 이끌고 마왕의 군대와 싸우고 있습니다. 매 라운드가 시작될 때 파티에는 사용할 수 있는 $m$ Ap(에너지 포인트)가 주어집니다.

각 캐릭터 $i$는 $a_i$의 피해를 주고 평소에 $c_i$ Ap를 소모하는 스킬을 가지고 있습니다. 어느 라운드에서든 각 캐릭터는 자신의 스킬을 한 번 사용하거나, 아무 비용 없이 아무것도 하지 않는 것 중 하나를 선택할 수 있습니다. 한 라운드에 사용된 모든 스킬의 총 Ap 소모량은 $m$을 초과할 수 없습니다. 라운드가 끝날 때 남은 Ap는 모두 버려지며, 다음 라운드를 위해 파티의 Ap는 $m$으로 완전히 회복됩니다.

이 게임의 독특한 메커니즘으로 인해, 어떤 캐릭터가 한 라운드에서 스킬을 사용하면 다음 라운드에서 그 스킬의 Ap 소모량은 $c_i + k$가 됩니다. 만약 캐릭터가 연속된 라운드에서 계속해서 스킬을 사용하더라도 소모량은 $c_i + k$로 유지됩니다(더 이상 증가하지 않습니다). 만약 캐릭터가 어떤 라운드에서 스킬을 사용하지 않으면, 바로 다음 라운드에서 스킬 소모량은 다시 $c_i$로 초기화됩니다.

Panda는 총 $R$번의 라운드 동안 입히는 총 피해량을 최대화하고 싶어 합니다. 가능한 최대 총 피해량을 구하세요.

입력

첫 번째 줄에는 테스트 케이스의 개수를 나타내는 정수 $T$ ($1 \le T \le 100$)가 주어집니다.

각 테스트 케이스의 첫 번째 줄에는 네 개의 정수 $n, m, k, R$ ($1 \le n \le 6$, $1 \le m, k \le 10^3$, $1 \le R \le 10^9$)이 주어집니다. $n$은 파티의 캐릭터 수, $m$은 매 라운드 시작 시 얻는 Ap, $k$는 스킬을 사용했을 때 일시적으로 증가하는 Ap 소모량, $R$은 전체 라운드 수입니다.

다음 $n$개의 줄에는 각각 캐릭터 $i$의 피해량과 초기 Ap 소모량을 나타내는 두 정수 $a_i, c_i$ ($1 \le a_i \le 10^6$, $1 \le c_i \le m$)가 주어집니다.

출력

달성할 수 있는 최대 총 피해량을 나타내는 정수 하나를 출력하세요.

예제

입력 1

3
3 7 1 5
59 3
13 2
81 4
5 14 2 9
66 8
20 2
25 4
39 6
57 7
4 13 7 16
18 2
13 5
33 4
7 1

출력 1

490
939
741

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
#2660EditorialOpen$O\left(\frac{8^n}{\sqrt n}+n^{3/2}4^n\right)\log R$ by GPT6 ProAnonymousView

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.