CF1809E.Two Tanks

普及/提高-

通过率:0%

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 ( 0ca0 \le c \le a ) liters of water initially, the second tank has dd ( 0db0 \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 > 0 , then you try to pour viv_i liters of water from the first tank into the second one. If vi<0v_i < 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 0ca0 \le c \le a and 0db0 \le d \le b , calculate the volume of water in the first tank after all operations are performed.

输入格式

The first line contains three integers n,an, a and bb ( 1n1041 \le n \le 10^4 ; 1a,b10001 \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 ( 1000vi1000-1000 \le v_i \le 1000 ; vi0v_i \neq 0 ) — the volume of water you try to pour in each operation.

输出格式

For all pairs of the initial volumes of water (c,d)(c, d) such that 0ca0 \le c \le a and 0db0 \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=i1c = i - 1 and d=j1d = 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 .

首页