#P11069. 「QMSOI R1」 生熏鱼

    ID: 12451 远端评测题 1500ms 1024MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>动态规划 DP搜索二分O2优化背包 DP

「QMSOI R1」 生熏鱼

Background

Everything started with a general called Shen Xun Yu...

So where is the connection between this problem and Shen Xun Yu?

Background

Problem Description

There are nn types of attacks. The ii-th type of attack will first give you aia_i experience points, and then make you lose bib_i health points.

You will be attacked in order for kk times. The type of the ii-th attack is cic_i. Your initial health is mm.

To gain more experience, you may choose any one of the nn attack types and prevent the first attack of that chosen type from affecting you. After preventing it, you will neither lose health nor gain experience from that attack.

Now you want to know: before your health drops to 00 or below, what is the maximum experience you can obtain.

Input Format

One line with 4 integers n,m,k,sn,m,k,s, where ss is the random seed. The meanings of the other variables are the same as in the statement.

Because the input is too large, you must generate the data in the following way:

const int M=1e9,C=1e5+5;
void read(){
    cin>>n>>m>>k>>s;
    mt19937 rand(s);
    for(int i=1;i<=n;i++)  a[i]=rand()%M+1,b[i]=rand()%C+1;
    for(int i=1;i<=k;i++)  c[i]=rand()%n+1;
}

The meanings of the arrays are the same as in the statement.

Output Format

Output one line with one integer, representing the maximum experience you can obtain.

2 100000 5 114514
3765807592

Hint

Sample Explanation

In sample 11, the data are a={953888980,904140652}a=\{953888980,904140652\}, b={6583,80624}b=\{6583,80624\}, c={1,2,1,1,2}c=\{1,2,1,1,2\}.

It is clear that you can either prevent no attack, or prevent the first attack of type 22, and obtain 953888980×3+904140652=3765807592953888980\times 3+904140652=3765807592 experience points.

It can be proven that there is no strategy that yields more experience.

Constraints

This problem uses bundled testing with subtasks. The score for each subtask is as follows: | Subtask | nn | kk | Score | | :----------: | :----------: | :----------: | :----------: | | 00 | 10\le 10 | 103\le 10^3 | 2020 | | 11 | 20\le 20 | 107\le 10^7 | 3030 | | 22 | 24\le 24 | 2×107\le 2\times 10^7 | 5050 |

For all testdata, it holds that 1n241\le n \le 24, 1k2×1071 \le k \le 2\times 10^7, 1s,m1091\le s,m\le 10^9

Translated by ChatGPT 5