QOJ.ac

QOJ

Límite de tiempo: 5 s Límite de memoria: 1024 MB Puntuación total: 100

#66. 兩道菜

Estadísticas

廚師 Bitaro 正喺參加一個烹飪比賽。呢個比賽要求參賽者煮兩道菜:IOI Donburi 同 JOI Curry。

IOI Donburi 嘅烹飪過程有 $N$ 個步驟。第 $i$ 個($1\le i\le N$)步驟啱啱需要 $A_i$ 分鐘。最初,佢只可以進行第一個步驟。要進行第 $i$ 個($2\le i\le N$)步驟,佢必須先完成第 $i-1$ 個步驟。

JOI Curry 嘅烹飪過程有 $M$ 個步驟。第 $j$ 個($1\le j\le M$)步驟啱啱需要 $B_j$ 分鐘。最初,佢只可以進行第一個步驟。要進行第 $j$ 個($2\le j\le M$)步驟,佢必須先完成第 $j-1$ 個步驟。

每個步驟都需要專心,所以一旦開始咗一個步驟,佢喺完成之前都唔可以進行其他步驟。喺兩個步驟之間,佢可以由一道菜轉去另一道菜。比賽一開始,佢就唔可以休息,直到完成兩道菜為止。

另外,呢個比賽會按以下方式畀參賽者藝術分。

  • 如果佢喺比賽開始後 $S_i$ 分鐘內完成 IOI Donburi 嘅第 $i$ 個($1\le i\le N$)烹飪步驟,就會得到 $P_i$ 分。呢度 $P_i$ 嘅值可能係負數。
  • 如果佢喺比賽開始後 $T_j$ 分鐘內完成 JOI Curry 嘅第 $j$ 個($1\le j\le M$)烹飪步驟,就會得到 $Q_j$ 分。呢度 $Q_j$ 嘅值可能係負數。

Bitaro 想令佢嘅藝術總分盡量高。

請寫一個程式,畀定烹飪步驟嘅數量、各步驟所需時間同藝術分嘅資訊,計算 Bitaro 可以得到嘅最高藝術總分。

輸入格式

從標準輸入讀取以下資料。輸入中所有值都係整數。

$$ \begin{array}{lll} N & M\\ A_1 & S_1 & P_1\\ \vdots\\ A_N & S_N & P_N\\ B_1 & T_1 & Q_1\\ \vdots\\ B_M & T_M & Q_M \end{array} $$

輸出格式

向標準輸出寫一行,內容係 Bitaro 可以得到嘅最高藝術總分。

資料範圍

  • $1\le N\le 1\,000\,000$。
  • $1\le M\le 1\,000\,000$。
  • $1\le A_i\le 1\,000\,000\,000$($1\le i\le N$)。
  • $1\le B_j\le 1\,000\,000\,000$($1\le j\le M$)。
  • $1\le S_i\le 2\,000\,000\,000\,000\,000=2\times 10^{15}$($1\le i\le N$)。
  • $1\le T_j\le 2\,000\,000\,000\,000\,000=2\times 10^{15}$($1\le j\le M$)。
  • $-1\,000\,000\,000\le P_i\le 1\,000\,000\,000$($1\le i\le N$)。
  • $-1\,000\,000\,000\le Q_j\le 1\,000\,000\,000$($1\le j\le M$)。

子任務

  1. (5 分)$N\le 200\,000$、$M\le 200\,000$、$S_1=\cdots=S_N=T_1=\cdots=T_M$。
  2. (3 分)$N\le 12$、$M\le 12$、$P_i=1$($1\le i\le N$)、$Q_j=1$($1\le j\le M$)。
  3. (7 分)$N\le 2\,000$、$M\le 2\,000$、$P_i=1$($1\le i\le N$)、$Q_j=1$($1\le j\le M$)。
  4. (39 分)$N\le 200\,000$、$M\le 200\,000$、$P_i=1$($1\le i\le N$)、$Q_j=1$($1\le j\le M$)。
  5. (11 分)$N\le 200\,000$、$M\le 200\,000$、$1\le P_i$($1\le i\le N$)、$1\le Q_j$($1\le j\le M$)。
  6. (9 分)$1\le P_i$($1\le i\le N$)、$1\le Q_j$($1\le j\le M$)。
  7. (17 分)$N\le 200\,000$、$M\le 200\,000$。
  8. (9 分)冇額外限制。

範例

輸入格式 1

4 3
2 1 1
3 8 1
2 13 1
1 13 1
3 6 1
2 11 1
2 15 1

輸出格式 1

6

說明

呢份範例輸入滿足子任務 2 嘅限制。

喺呢份範例輸入入面,Bitaro 例如可以按以下次序進行烹飪步驟:

  1. 佢進行 JOI Curry 嘅第 1 個步驟,喺比賽開始後 3 分鐘完成。因為冇超過 6 分鐘,所以得到 1 分。
  2. 佢進行 IOI Donburi 嘅第 1 個步驟,喺比賽開始後 5 分鐘完成。因為超過咗 1 分鐘,所以得唔到藝術分。
  3. 佢進行 IOI Donburi 嘅第 2 個步驟,喺比賽開始後 8 分鐘完成。因為冇超過 8 分鐘,所以得到 1 分。
  4. 佢進行 JOI Curry 嘅第 2 個步驟,喺比賽開始後 10 分鐘完成。因為冇超過 11 分鐘,所以得到 1 分。
  5. 佢進行 IOI Donburi 嘅第 3 個步驟,喺比賽開始後 12 分鐘完成。因為冇超過 13 分鐘,所以得到 1 分。
  6. 佢進行 IOI Donburi 嘅第 4 個步驟,喺比賽開始後 13 分鐘完成。因為冇超過 13 分鐘,所以得到 1 分。
  7. 佢進行 JOI Curry 嘅第 3 個步驟,喺比賽開始後 15 分鐘完成。因為冇超過 15 分鐘,所以得到 1 分。

呢度嘅藝術總分係 6 分。佢唔可能得到超過 6 分,所以輸出 6。

輸入格式 2

5 7
16 73 16
17 73 10
20 73 1
14 73 16
18 73 10
3 73 2
10 73 7
16 73 19
12 73 4
15 73 15
20 73 14
15 73 8

輸出格式 2

63

說明

呢份範例輸入滿足子任務 1 嘅限制。

輸入格式 3

9 11
86 565 58
41 469 -95
73 679 28
91 585 -78
17 513 -63
48 878 -66
66 901 59
72 983 -70
68 1432 11
42 386 -87
36 895 57
100 164 10
96 812 -6
23 961 -66
54 193 51
37 709 82
62 148 -36
28 853 22
15 44 53
77 660 -19

輸出格式 3

99

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
EditorialOpen Official EditorialQingyu- Download
#251EditorialOpen题解jianglyView

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.