CF1809E.Two Tanks

提高+/省选-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

There are two water tanks, the first one fits aa liters of water, the second one fits bb liters of water. The first tank has cc (0≤c≤a0 \le c \le a) liters of water initially, the second tank has dd (0≤d≤b0 \le d \le b) liters of water initially.

You want to perform nn operations on them. The ii-th operation is specified by a single non-zero integer viv_i. If vi>0v_i \gt 0, then you try to pour viv_i liters of water from the first tank into the second one. If vi<0v_i \lt 0, you try to pour −vi-v_i liters of water from the second tank to the first one.

When you try to pour xx liters of water from the tank that has yy liters currently available to the tank that can fit zz more liters of water, the operation only moves min⁡(x,y,z)\min(x, y, z) liters of water.

For all pairs of the initial volumes of water (c,d)(c, d) such that 0≤c≤a0 \le c \le a and 0≤d≤b0 \le d \le b, calculate the volume of water in the first tank after all operations are performed.

有两个水箱,第一个水箱容量为 aa 升,第二个水箱容量为 bb 升。初始时,第一个水箱中有 cc(0≤c≤a0 \le c \le a)升水,第二个水箱中有 dd(0≤d≤b0 \le d \le b)升水。

你需要对这两个水箱执行 nn 次操作。第 ii 次操作由一个非零整数 viv_i 指定:若 vi>0v_i > 0,则尝试从第一个水箱向第二个水箱倾倒 viv_i 升水;若 vi<0v_i < 0,则尝试从第二个水箱向第一个水箱倾倒 −vi-v_i 升水。

当尝试从当前含有 yy 升水的水箱向尚有 zz 升剩余容量的水箱倾倒 xx 升水时,实际转移的水量为 min⁡(x,y,z)\min(x, y, z) 升。

对所有满足 0≤c≤a0 \le c \le a 且 0≤d≤b0 \le d \le b 的初始水量对 (c,d)(c, d),计算全部操作执行完毕后第一个水箱中的水量。

输入格式

The first line contains three integers n,an, a and bb (1≤n≤1041 \le n \le 10^4; 1≤a,b≤10001 \le a, b \le 1000) — the number of operations and the capacities of the tanks, respectively.

The second line contains nn integers v1,v2,…,vnv_1, v_2, \dots, v_n (−1000≤vi≤1000-1000 \le v_i \le 1000; vi≠0v_i \neq 0) — the volume of water you try to pour in each operation.

第一行包含三个整数 nn、aa 和 bb(1≤n≤1041 \le n \le 10^4;1≤a,b≤10001 \le a, b \le 1000),分别表示操作次数以及两个水箱的容量。

第二行包含 nn 个整数 v1,v2,…,vnv_1, v_2, \dots, v_n(−1000≤vi≤1000-1000 \le v_i \le 1000;vi≠0v_i \neq 0),表示每次操作中试图注入的水量。

输出格式

For all pairs of the initial volumes of water (c,d)(c, d) such that 0≤c≤a0 \le c \le a and 0≤d≤b0 \le d \le b, calculate the volume of water in the first tank after all operations are performed.

Print a+1a + 1 lines, each line should contain b+1b + 1 integers. The jj-th value in the ii-th line should be equal to the answer for c=i−1c = i - 1 and d=j−1d = j - 1.

对于所有满足 0≤c≤a0 \le c \le a 和 0≤d≤b0 \le d \le b 的初始水量对 (c,d)(c, d),计算执行完所有操作后第一个水箱中的水量。

输出 a+1a + 1 行,每行包含 b+1b + 1 个整数。第 ii 行的第 jj 个数值应等于 c=i−1c = i - 1 且 d=j−1d = j - 1 时的答案。

输入输出样例

  • 输入#1

    3 4 4
    -2 1 2

    输出#1

    0 0 0 0 0 
    0 0 0 0 1 
    0 0 1 1 2 
    0 1 1 2 3 
    1 1 2 3 4
  • 输入#2

    3 9 5
    1 -2 2

    输出#2

    0 0 0 0 0 0 
    0 0 0 0 0 1 
    0 1 1 1 1 2 
    1 2 2 2 2 3 
    2 3 3 3 3 4 
    3 4 4 4 4 5 
    4 5 5 5 5 6 
    5 6 6 6 6 7 
    6 7 7 7 7 8 
    7 7 7 7 8 9

说明/提示

Consider c=3c = 3 and d=2d = 2 from the first example:

  • The first operation tries to move 22 liters of water from the second tank to the first one, the second tank has 22 liters available, the first tank can fit 11 more liter. Thus, min⁡(2,2,1)=1\min(2, 2, 1) = 1 liter is moved, the first tank now contains 44 liters, the second tank now contains 11 liter.
  • The second operation tries to move 11 liter of water from the first tank to the second one. min⁡(1,4,3)=1\min(1, 4, 3) = 1 liter is moved, the first tank now contains 33 liters, the second tank now contains 22 liter.
  • The third operation tries to move 22 liter of water from the first tank to the second one. min⁡(2,3,2)=2\min(2, 3, 2) = 2 liters are moved, the first tank now contains 11 liter, the second tank now contains 44 liters.

There's 11 liter of water in the first tank at the end. Thus, the third value in the fourth row is 11.

考虑第一个例子中的 c=3c = 3 和 d=2d = 2:

  • 第一次操作尝试将 22 升水从第二个水箱转移到第一个水箱;第二个水箱当前有 22 升水可用,而第一个水箱还能容纳 11 升水。因此,实际转移水量为 min⁡(2,2,1)=1\min(2, 2, 1) = 1 升;转移后,第一个水箱含水量变为 44 升,第二个水箱含水量变为 11 升。
  • 第二次操作尝试将 11 升水从第一个水箱转移到第二个水箱;实际转移水量为 min⁡(1,4,3)=1\min(1, 4, 3) = 1 升;转移后,第一个水箱含水量变为 33 升,第二个水箱含水量变为 22 升。
  • 第三次操作尝试将 22 升水从第一个水箱转移到第二个水箱;实际转移水量为 min⁡(2,3,2)=2\min(2, 3, 2) = 2 升;转移后,第一个水箱含水量变为 11 升,第二个水箱含水量变为 44 升。

最终,第一个水箱中剩余 11 升水。因此,第四行的第三个值为 11。

输入解题思路,AI测评打分。不知道怎么写?

首页