#P16401. [ECUSTPC 2026 Spring] 星露谷物语
[ECUSTPC 2026 Spring] 星露谷物语
Background
:::epigraph Prepare... to plant... crops! :::
Problem Description
Nailong is addicted to Stardew Valley during the holiday. To complete all achievements, he needs a lot of gold to buy the Golden Clock, so he urgently needs money now.
In Stardew Valley, players can plant different crops. By planting crops, player Nailong can earn the gold he needs.
It is the morning of day in spring. Spring lasts for a total of days. Nailong has some farmland that can be cultivated; initially, all plots are idle. He has gold in hand, and now he starts working for spring.
Pierre's shop sells kinds of single-harvest crop seeds and kinds of regrowable crop seeds. They are defined as follows:
- Single-harvest crops: each seed costs gold, each harvested crop sells for gold, and the growth time is days. That is, a crop planted on day becomes harvestable on day . After harvesting, the crop is removed and the plot becomes idle.
- Regrowable crops: each seed costs gold, each harvested crop sells for gold, and the growth time is days. That is, a crop planted on day becomes harvestable on day . Meanwhile, it has a regrowth cycle of days. After harvesting, the crop is not removed, and a crop harvested on day will become harvestable again on day .
- On day , spring ends and summer arrives. All crops in the farmland will wither and cannot be harvested, even if they would have matured on that day.
Because Nailong is lazy, throughout the whole spring he will choose at most one crop (among these crops) to plant. Once he chooses a crop, he will not plant any other crop for the rest of spring.
Each day, Nailong may perform the following operations any number of times, and the order of operations within the same day can be arranged arbitrarily. If a plot becomes idle on that day due to harvesting, it can still be planted again on the same day:
- Buy seeds from Pierre's seed shop.
- Plant one seed on an idle plot.
- Harvest one harvestable crop and sell it.
- Note that you cannot remove an existing crop from the land, unless it is a single-harvest crop being harvested.
Since all plantable plots are equivalent, he wants to know the maximum profit (in gold) that a single plot of farmland can bring him by the end of spring.
Note that if no profit can be made no matter what, Nailong can do nothing and obtain a profit of gold at the end of spring.
Input Format
The first line contains an integer , denoting the number of testdata.
For each testdata, the first line contains three integers $n, m, k\ (1 \le n + m \le 10^5, n \ge 0, m \ge 0, 2 \le k \le 10^9)$, representing the number of single-harvest crops, the number of regrowable crops, and the number of days in spring.
The next lines each contain three integers , representing the seed price, the selling price of the harvested crop, and the growth time of a single-harvest crop.
The next lines each contain four integers $p, q, t, s\ (0 \le p, q \le 10^9, 1 \le t, s \le k - 1)$, representing the seed price, the selling price of the harvested crop, the growth time, and the regrowth cycle of a regrowable crop.
It is guaranteed that over all testdata.
Output Format
For each testdata, output one integer per line, denoting the maximum profit in gold that a single plot of farmland can bring him by the end of spring.
3
2 1 10
20 50 3
5 7 1
30 15 2 2
0 2 7
10 4 2 1
25 9 1 2
1 1 5
10 8 2
5 1 4 1
90
10
0
Hint
Sample 1 Explanation
For the first testdata, we have the following crops:
| Crop | Type | Seed Price | Crop Price | Growth Time | Regrowth Cycle |
|---|---|---|---|---|---|
| A | Single-harvest | 20 | 50 | 3 | N/A |
| B | 5 | 7 | 1 | ||
| C | Regrowable | 30 | 15 | 2 | |
Consider choosing crop A. One feasible plan is as follows:
| Day | Action | Net Income That Day |
|---|---|---|
| 1 | Buy 3 seeds of crop A and plant one crop A | -60 |
| 4 | Harvest and sell one harvestable crop A, plant crop A | 50 |
| 7 | ||
| 10 | Harvest and sell one harvestable crop A |
The total profit is gold.
Translated by ChatGPT 5