English · Original
Chinese · Translation
Formal · Original
Alice likes snow a lot! Unfortunately, this year's winter is already over, and she can't expect to have any more of it. Bob has thus bought her a gift — a large snow maker. He plans to make some amount of snow every day. On day _i_ he will make a pile of snow of volume _V__i_ and put it in her garden.
Each day, every pile will shrink a little due to melting. More precisely, when the temperature on a given day is _T__i_, each pile will reduce its volume by _T__i_. If this would reduce the volume of a pile to or below zero, it disappears forever. All snow piles are independent of each other.
Note that the pile made on day _i_ already loses part of its volume on the same day. In an extreme case, this may mean that there are no piles left at the end of a particular day.
You are given the initial pile sizes and the temperature on each day. Determine the total volume of snow melted on each day.
## Input
The first line contains a single integer _N_ (1 ≤ _N_ ≤ 105) — the number of days.
The second line contains _N_ integers _V_1, _V_2, ..., _V__N_ (0 ≤ _V__i_ ≤ 109), where _V__i_ is the initial size of a snow pile made on the day _i_.
The third line contains _N_ integers _T_1, _T_2, ..., _T__N_ (0 ≤ _T__i_ ≤ 109), where _T__i_ is the temperature on the day _i_.
## Output
Output a single line with _N_ integers, where the _i_\-th integer represents the total volume of snow melted on day _i_.
[samples]
## Note
In the first sample, Bob first makes a snow pile of volume 10, which melts to the size of 5 on the same day. On the second day, he makes another pile of size 10. Since it is a bit warmer than the day before, the first pile disappears completely while the second pile shrinks to 3. At the end of the second day, he has only a single pile of size 3. On the third day he makes a smaller pile than usual, but as the temperature dropped too, both piles survive till the end of the day.
Alice 非常喜欢雪!但不幸的是,今年的冬天已经结束,她再也无法等到更多的雪了。因此,Bob 给她买了一个礼物——一台大型造雪机。他计划每天制造一定量的雪。在第 #cf_span[i] 天,他会制造一个体积为 #cf_span[Vi] 的雪堆,并将其放在她的花园里。
每天,每个雪堆都会因融化而略微缩小。更准确地说,当某天的温度为 #cf_span[Ti] 时,每个雪堆的体积会减少 #cf_span[Ti]。如果这会导致某个雪堆的体积减少到零或以下,则该雪堆将永久消失。所有雪堆彼此独立。
请注意,第 #cf_span[i] 天制造的雪堆在当天就会开始融化。极端情况下,这意味着在某一天结束时可能没有任何雪堆剩余。
给你每个雪堆的初始体积和每天的温度,请确定每天融化的雪的总体积。
第一行包含一个整数 #cf_span[N] (#cf_span[1 ≤ N ≤ 105]) —— 天数。
第二行包含 #cf_span[N] 个整数 #cf_span[V1, V2, ..., VN] (#cf_span[0 ≤ Vi ≤ 109]),其中 #cf_span[Vi] 表示第 #cf_span[i] 天制造的雪堆的初始体积。
第三行包含 #cf_span[N] 个整数 #cf_span[T1, T2, ..., TN] (#cf_span[0 ≤ Ti ≤ 109]),其中 #cf_span[Ti] 表示第 #cf_span[i] 天的温度。
请输出一行包含 #cf_span[N] 个整数,其中第 #cf_span[i] 个整数表示第 #cf_span[i] 天融化的雪的总体积。
在第一个样例中,Bob 首先制造了一个体积为 10 的雪堆,当天融化后剩余体积为 5。第二天,他又制造了一个体积为 10 的雪堆。由于气温比前一天略高,第一个雪堆完全融化,而第二个雪堆缩小到 3。到第二天结束时,只剩下体积为 3 的一个雪堆。第三天,他制造了一个比平时小的雪堆,但气温也下降了,因此两个雪堆都存活到了当天结束。
## Input
第一行包含一个整数 #cf_span[N] (#cf_span[1 ≤ N ≤ 105]) —— 天数。第二行包含 #cf_span[N] 个整数 #cf_span[V1, V2, ..., VN] (#cf_span[0 ≤ Vi ≤ 109]),其中 #cf_span[Vi] 表示第 #cf_span[i] 天制造的雪堆的初始体积。第三行包含 #cf_span[N] 个整数 #cf_span[T1, T2, ..., TN] (#cf_span[0 ≤ Ti ≤ 109]),其中 #cf_span[Ti] 表示第 #cf_span[i] 天的温度。
## Output
请输出一行包含 #cf_span[N] 个整数,其中第 #cf_span[i] 个整数表示第 #cf_span[i] 天融化的雪的总体积。
[samples]
## Note
在第一个样例中,Bob 首先制造了一个体积为 10 的雪堆,当天融化后剩余体积为 5。第二天,他又制造了一个体积为 10 的雪堆。由于气温比前一天略高,第一个雪堆完全融化,而第二个雪堆缩小到 3。到第二天结束时,只剩下体积为 3 的一个雪堆。第三天,他制造了一个比平时小的雪堆,但气温也下降了,因此两个雪堆都存活到了当天结束。
**Definitions**
Let $ N \in \mathbb{Z}^+ $ be the number of days.
For each day $ i \in \{1, \dots, N\} $:
- $ V_i \in \mathbb{R}_{\geq 0} $: initial volume of snow pile made on day $ i $.
- $ T_i \in \mathbb{R}_{\geq 0} $: temperature on day $ i $.
Let $ S_i^{(d)} $ be the volume of the pile made on day $ i $ at the start of day $ d $, for $ d \geq i $.
Initially, $ S_i^{(i)} = V_i $.
**Constraints**
1. $ 1 \leq N \leq 10^5 $
2. $ 0 \leq V_i \leq 10^9 $ for all $ i \in \{1, \dots, N\} $
3. $ 0 \leq T_i \leq 10^9 $ for all $ i \in \{1, \dots, N\} $
**Dynamics**
For each pile $ i $ and each subsequent day $ d \geq i $:
- If $ S_i^{(d)} > 0 $, then on day $ d $, it melts by $ \min(S_i^{(d)}, T_d) $, and:
$$
S_i^{(d+1)} = \max(0, S_i^{(d)} - T_d)
$$
- If $ S_i^{(d)} = 0 $, then $ S_i^{(d+1)} = 0 $.
**Objective**
For each day $ d \in \{1, \dots, N\} $, compute the total melted volume:
$$
M_d = \sum_{i=1}^{d} \min(S_i^{(d)}, T_d)
$$
where $ S_i^{(d)} = \max\left(0, V_i - \sum_{j=i}^{d-1} T_j\right) $ for $ d > i $, and $ S_i^{(i)} = V_i $.
API Response (JSON)
{
"problem": {
"name": "C. Producing Snow",
"description": {
"content": "Alice likes snow a lot! Unfortunately, this year's winter is already over, and she can't expect to have any more of it. Bob has thus bought her a gift — a large snow maker. He plans to make some amoun",
"description_type": "Markdown"
},
"platform": "Codeforces",
"limit": {
"time_limit": 1000,
"memory_limit": 262144
},
"difficulty": "None",
"is_remote": true,
"is_sync": true,
"sync_url": null,
"sign": "CF948C"
},
"statements": [
{
"statement_type": "Markdown",
"content": "Alice likes snow a lot! Unfortunately, this year's winter is already over, and she can't expect to have any more of it. Bob has thus bought her a gift — a large snow maker. He plans to make some amoun...",
"is_translate": false,
"language": "English"
},
{
"statement_type": "Markdown",
"content": "Alice 非常喜欢雪!但不幸的是,今年的冬天已经结束,她再也无法等到更多的雪了。因此,Bob 给她买了一个礼物——一台大型造雪机。他计划每天制造一定量的雪。在第 #cf_span[i] 天,他会制造一个体积为 #cf_span[Vi] 的雪堆,并将其放在她的花园里。\n\n每天,每个雪堆都会因融化而略微缩小。更准确地说,当某天的温度为 #cf_span[Ti] 时,每个雪堆的体积会减少 #cf_sp...",
"is_translate": true,
"language": "Chinese"
},
{
"statement_type": "Markdown",
"content": "**Definitions** \nLet $ N \\in \\mathbb{Z}^+ $ be the number of days. \nFor each day $ i \\in \\{1, \\dots, N\\} $: \n- $ V_i \\in \\mathbb{R}_{\\geq 0} $: initial volume of snow pile made on day $ i $. \n- $ ...",
"is_translate": false,
"language": "Formal"
}
]
}