luogu#P16370. [OOI 2026] Monsters and Swords

[OOI 2026] Monsters and Swords

Problem Description

Given nn monsters arranged in a row, for each monster, two values are known: hih_i --- the health of the monster and rir_i --- the reward for defeating this monster, expressed in coins. The knight must defeat all the monsters.

For fighting the monsters, the knight has mm types of swords, and for each type of sword, its characteristics are known: sjs_j --- the strength of the sword and cjc_j --- the price of the sword in coins. To purchase a sword with price cjc_j, the knight must have at least cjc_j coins. After purchasing a sword, the knight's coin count decreases by cjc_j. Initially, the knight has xx coins.

After purchasing a sword, it can be used no more than kk times in battles against the monsters. Any type of sword can be purchased an arbitrary number of times. A sword with strength sjs_j can kill a monster with health hih_i if sjhis_j \geq h_i. At any moment, the knight can only possess one sword, meaning that after purchasing a new sword, the old sword can no longer be used (but it can be purchased again in the future).

The monsters must be defeated in a fixed order: from the first to the last. It is required to determine whether the knight can do this.

Input Format

The first line contains four integers nn, mm, kk, and xx (1n,m5000001 \le n, m \le 500\,000, 1kn1 \le k \le n, 1x1091 \le x \le 10^9) --- the number of monsters, the number of sword types, the maximum number of times a sword can be used, and the initial number of coins the knight has.

In the following nn lines, the descriptions of the monsters are given. In the ii-th line, there are two integers: hih_i and rir_i (1hi,ri109)1 \le h_i, r_i \le 10^9) --- the health of the ii-th monster and the reward for defeating it.

In the next mm lines, the characteristics of the swords are described. In the jj-th line, there are two integers sjs_j and cjc_j (1sj,cj109)1 \le s_j, c_j \le 10^9) --- the strength and price of the jj-th sword.

Output Format

Print Yes\texttt{Yes} (without quotes) if the knight can defeat all the monsters, and No\texttt{No} (without quotes) otherwise.

3 3 2 5
1 1
5 5
9 5
9 10
1 1
5 1
Yes
5 5 5 6
3 6
2 4
1 1
4 4
8 4
2 7
7 7
3 4
5 9
6 4
No

Hint

Note

In the first example, the knight can first buy the third sword, using it to defeat the first and second monsters. After that, he will have 51+1+5=105 - 1 + 1 + 5 = 10 coins. This allows him to buy the first sword and defeat the last monster.

In the second example, the knight cannot defeat all the monsters because there is no type of sword that can defeat the fifth monster.

Scoring

The tests for this problem consist of 9 groups. Points for each group are awarded only if all tests of the group and all tests of some previous groups are passed. Note that passing the tests from the statement is not required for some groups. Offline testing means that the results of testing your solution on this group will only be available after the competition ends. The final score for each group is equal to the maximum score obtained for this group of tests across all submitted solutions.

Group Points Additional constraints < Required groups Comment
nn mm kk
00 -- -- -- Tests from the statement.
11 1111 k=1k=1 --
22 99 n100n \leq 100 m100m \leq 100 k=nk=n
33 1414 n100000n \leq 100\,000 m3000m \leq 3000 22
44 1616 -- 2,32, 3
55 77 n400n \leq 400 m400m \leq 400 -- 0,20, 2
66 88 n3000n \leq 3000 m3000m \leq 3000 0,2,50, 2, 5
77 1010 n150000n \leq 150\,000 m150000m \leq 150\,000 0,2,3,5,60, 2, 3, 5, 6
88 1212 n300000n \leq 300\,000 m300000m \leq 300\,000 0,2,3,50, 2, 3, 5 -- 77
99 1313 -- 00 -- 88 Offline testing.