#P10010. [集训队互测 2023] Grievous Lady

    ID: 11364 远端评测题 2000ms 1024MiB 尝试: 0 已通过: 0 难度: 9 上传者: 标签>动态规划 DP数学集训队互测2023爬山算法 Local search模拟退火随机调整线性规划概率论线性代数随机化

[集训队互测 2023] Grievous Lady

Background

Tairitsu entered from that gloomy tower, step by step going deeper into this twisted maze.

A sudden stabbing pain struck Tairitsu’s heart.

Tairitsu stepped back, stumbled, and then fell to their knees.

Before Tairitsu could even touch it, the dark gray-black floor suddenly cracked and collapsed, falling downward first.

The conflict fragments collected earlier, together with the tower itself, turned into a torrential rain, surrounding Tairitsu.

A strange phenomenon suddenly appeared, and Tairitsu’s mind fell into chaos.

The tower fell into the joyful ocean made of light fragments from before, but Tairitsu was tightly wrapped by conflict fragments.

Within the storm where light and conflict fragments intertwined, the only things Tairitsu could see were those disgusting conflict fragments.

That memory from the end of the world came into Tairitsu’s sight.

Facing the scene of the world slowly moving toward its end, Tairitsu’s reason was shattering.

Tairitsu realized that all beautiful memories are only for a moment, and in the end they will all head toward destruction.

The fragments around were still swirling, and Tairitsu tried to see clearly the changes of those glass fragments.

Tairitsu realized that the fragments surrounding them were now operating in the most terrifying way.

The “melancholy level” brought by this fragment storm can be simply described as the sum of the rotation speeds of the outer fragments multiplied by the sum of the rotation speeds of the inner fragments.

A glass fragment always spins forward at one speed on the outer side, and always spins backward at another speed on the inner side.

Each fragment is an instant memory from a different world, so its rotation speeds can always be considered as independently randomly assigned.

When the little remaining hope was about to be completely extinguished, Tairitsu only wanted to know: for the current fragment storm, what exactly is the melancholy level, that is, the maximum possible melancholy level?

Problem Description

There are nn elements, numbered 1n1\sim n. Each element jj has two positive integer weights aj,bja_j,b_j.

You need to determine a subset SS of [1,n]N[1,n]\cap\mathbb N to maximize

$$\left(\sum_{k=1}^na_k[k\in S]\right)\left(\sum_{k=1}^nb_k[k\notin S]\right)$$

This problem is obviously infeasible, so it is guaranteed that each aj,bja_j,b_j is generated independently and uniformly at random within [1,A]N[1,A]\cap\mathbb N and [1,B]N[1,B]\cap\mathbb N, respectively.

Now given n,A,Bn,A,B and the two weights (aj,bj)(a_j,b_j) of each element, please compute the maximum answer.

Input Format

There are multiple sets of testdata in each test point.

The first line contains four integers T,n,A,BT,n,A,B. TT denotes the number of datasets in this group, and n,A,Bn,A,B indicate that all datasets in this test point share the same n,A,Bn,A,B.

Then each dataset consists of nn lines. In the jj-th line there are two integers aj,bja_j,b_j.

It is guaranteed that aj,bja_j,b_j are generated independently and uniformly at random within the corresponding ranges.

Output Format

For each dataset, output one integer per line, which is the answer.

Note that the answer may be very large. You may need to use the __int128 type for intermediate storage and computation, and then print the result. Note that you may need to use some correct output methods.

Hint

Sample I/O

Because the data size of this problem is too large, submitting directly for judging will put a lot of pressure on the judge machine. This problem will provide many large samples; please try to reduce the number of submissions.

Please refer to the attached files grievouslady*.in/ans, a total of 5050 groups, basically generated according to the partial-score approach.

Since this problem guarantees random data, no hand-written samples are provided.

Constraints and Hints

For all data, it is guaranteed that 10n300010\le n\le3000, 104A,B101210^4\le A,B\le10^{12}, 1T501\le T\le50.

This problem has subtasks; there are a total of 100100 test points. The detailed distribution of test points can be seen in the table below.

The version of this problem on Luogu does not have subtasks.

(Because the table is relatively wide, it is hard to display it completely on Luogu. You may need to use the “Expand” function on the problem page.)

Test Point ID nn AA BB Test Point ID nn AA BB Test Point ID nn AA BB
121\sim2 =10=10 =104=10^4 333433\sim34 =100=100 =104=10^4 676867\sim68 =1000=1000 =105=10^5 =1012=10^{12}
343\sim4 =109=10^9 353635\sim36 =105=10^5 =105=10^5 697069\sim70 =109=10^9
565\sim6 =1012=10^{12} 373837\sim38 =109=10^9 717271\sim72 =1012=10^{12} =1012=10^{12}
787\sim8 =20=20 =104=10^4 394039\sim40 =109=10^9 737473\sim74 =1500=1500 =105=10^5
9109\sim10 =109=10^9 414241\sim42 =1012=10^{12} =1012=10^{12} 757675\sim76 =109=10^9
111211\sim12 =1012=10^{12} 434443\sim44 =200=200 =105=10^5 777877\sim78 =1012=10^{12} =1012=10^{12}
131413\sim14 =30=30 =104=10^4 454645\sim46 =109=10^9 798079\sim80 =2000=2000 =105=10^5
151615\sim16 =109=10^9 474847\sim48 =1012=10^{12} =1012=10^{12} 818281\sim82 =109=10^9
171817\sim18 =1012=10^{12} 495049\sim50 =300=300 =105=10^5 838483\sim84 =1012=10^{12}
192019\sim20 =40=40 =104=10^4 515251\sim52 =109=10^9 858685\sim86 =2500=2500 =104=10^4 =109=10^9
212221\sim22 =109=10^9 535453\sim54 =1012=10^{12} =1012=10^{12} 878887\sim88 =105=10^5 =1012=10^{12}
232423\sim24 =1012=10^{12} 555655\sim56 =500=500 =105=10^5 899089\sim90 =109=10^9
252625\sim26 =50=50 =104=10^4 =104=10^4 575857\sim58 =109=10^9 919291\sim92 =1012=10^{12}
272827\sim28 =109=10^9 596059\sim60 =1012=10^{12} =1012=10^{12} 939493\sim94 =3000=3000 =104=10^4 =109=10^9
293029\sim30 =109=10^9 616261\sim62 =800=800 =105=10^5 959695\sim96 =105=10^5 =1012=10^{12}
313231\sim32 =1012=10^{12} 636463\sim64 =109=10^9 979897\sim98 =109=10^9
656665\sim66 =1012=10^{12} 9910099\sim100 =1012=10^{12}

We arrange the test points in the following way:

  • subtask 11: 1121\sim12, worth 12pts\rm12pts.
  • subtask 22: 133213\sim32, worth 20pts\rm20pts.
  • subtask 33: 333633\sim36, worth 4pts\rm4pts.
  • subtask 44: 374837\sim48, worth 12pts\rm12pts.
  • subtask 55: 495049\sim50, worth 2pts\rm2pts.
  • subtask 66: 516051\sim60, worth 10pts\rm10pts.
  • subtask 77: 617261\sim72, worth 12pts\rm12pts.
  • subtask 88: 738473\sim84, worth 12pts\rm12pts.
  • subtask 99: 859285\sim92, worth 8pts\rm8pts.
  • subtask 1010: 9310093\sim100, worth 8pts\rm8pts.

This problem has no subtask dependencies, so please make sure your algorithm is correct after testing on samples before submitting, to avoid stressing the judge machine.

Epilogue

This world—everything—comes from the past. Images of the past, even joyful memories, are like the night after day, gradually leading to this apocalypse.

Tears filled their eyes. Tairitsu’s gaze turned into darkness.

Tairitsu resonated with these shards of glass, and the shell of memories swirling around began to crack.

Tairitsu stood within it, in front of that dazzling light, already without any feelings.

The twisted maze, under Tairitsu’s power, was completely destroyed...

As time passed, Tairitsu changed. No longer passionately collecting memories, but walking through this world almost unconsciously, and no longer holding any ambition.

Now, Tairitsu is walking beside a ruined collapsed building, spinning a parasol that was once found in the rubble.

Input Format

There are multiple sets of testdata in each test point.

The first line contains four integers, T,n,A,BT,n,A,B. TT denotes the number of datasets in this group, and n,A,Bn,A,B indicate that all datasets in this test point share the same n,A,Bn,A,B.

Then each dataset consists of nn lines, where the jj-th line contains two integers aj,bja_j,b_j.

It is guaranteed that aj,bja_j,b_j are generated independently and uniformly at random within the corresponding ranges.

Output Format

For each dataset, output one line containing one integer, representing the answer.

Note that this answer may be very large. You may need to use the __int128 type for intermediate storage and computation, and finally print it. Note that you may need to use some correct output methods.

Hint

Sample I/O

Because the data size of this problem is too large, submitting directly for judging will put a lot of pressure on the judge machine. This problem will provide many large samples; please try to reduce the number of submissions.

Please refer to the attached files grievouslady*.in/ans, a total of 5050 groups, basically generated according to the partial-score approach.

Since this problem guarantees random data, no hand-written samples are provided.

Constraints and Hints

For all data, it is guaranteed that 10n300010\le n\le3000, 104A,B101210^4\le A,B\le10^{12}, 1T501\le T\le50.

This problem has subtasks; there are a total of 100100 test points. The detailed test point distribution can be found in the table above.

The version of this problem on Luogu does not have subtasks.

Translated by ChatGPT 5