#4. 浇水

浇水

说明

小珅和小美打算给花园里的 <math xmlns="http://www.w3.org/1998/Math/MathML">n 株植物浇水。
植物排成一行,编号从左到右依次从 <math xmlns="http://www.w3.org/1998/Math/MathML">1 到 <math xmlns="http://www.w3.org/1998/Math/MathML">n。其中,第 <math xmlns="http://www.w3.org/1998/Math/MathML">i(1in) 株植物的位置 <math xmlns="http://www.w3.org/1998/Math/MathML">x=i,需要浇的水量为 <math xmlns="http://www.w3.org/1998/Math/MathML">wi 升。小珅和小美每人有一个水罐,其中小珅的水罐容量为 <math xmlns="http://www.w3.org/1998/Math/MathML">A 升,小美的水罐的容量为 <math xmlns="http://www.w3.org/1998/Math/MathML">B 升,初始时,两个水罐都装满了水。
小珅从左到右给植物浇水,从第 <math xmlns="http://www.w3.org/1998/Math/MathML">1 株植物开始。小美从右到左给植物浇水,从第 <math xmlns="http://www.w3.org/1998/Math/MathML">n 株植物开始。他们俩同时开始给植物浇水。
小珅和小美各自为每株植物浇水时,每分钟浇 <math xmlns="http://www.w3.org/1998/Math/MathML">1 升水,也就是每过去一分钟,水罐中的水减少 <math xmlns="http://www.w3.org/1998/Math/MathML">1 升,植物还需要浇的水也减少 <math xmlns="http://www.w3.org/1998/Math/MathML">1 升。如果当前植物所需浇水量减为 <math xmlns="http://www.w3.org/1998/Math/MathML">0,就移动到下一棵植物(对于小珅是编号大 <math xmlns="http://www.w3.org/1998/Math/MathML">1 的植物,对于小美是编号小 <math xmlns="http://www.w3.org/1998/Math/MathML">1 的植物),移动的时间忽略不计。
如果浇水途中水罐中的水耗尽了,一个超强水泵会用 <math xmlns="http://www.w3.org/1998/Math/MathML">T 分钟的时间,重新灌满水罐,然后重新开始浇水。
如果某人到达一株植物时,另一个人已经先到了,那么就只让先到的人浇水。如果小珅和小美同时到达,就让小珅完成浇水。
请你实现一个程序,求为所有植物完成浇水的时间。

输入格式

第 <math xmlns="http://www.w3.org/1998/Math/MathML">1 行包含 <math xmlns="http://www.w3.org/1998/Math/MathML">4 个正整数 <math xmlns="http://www.w3.org/1998/Math/MathML">n,A,B,T

第 <math xmlns="http://www.w3.org/1998/Math/MathML">2 行,<math xmlns="http://www.w3.org/1998/Math/MathML">n 个正整数 <math xmlns="http://www.w3.org/1998/Math/MathML">w1,w2,,wn

输出格式

输出一行,一个整数,表示答案。
5 1 9 5
7 3 2 3 2 
37

提示

样例 1: 小珅的水罐只能装 <math xmlns="http://www.w3.org/1998/Math/MathML">1 升水,第 <math xmlns="http://www.w3.org/1998/Math/MathML">1 株植物需要 <math xmlns="http://www.w3.org/1998/Math/MathML">7 升水,小珅要重新灌 <math xmlns="http://www.w3.org/1998/Math/MathML">6 次水,总共用时 <math xmlns="http://www.w3.org/1998/Math/MathML">7+5×6=37 分钟。然后小珅在第 <math xmlns="http://www.w3.org/1998/Math/MathML">37 分钟走到第 <math xmlns="http://www.w3.org/1998/Math/MathML">2 株植物,且水罐里没有水。

小美的水罐可以装 <math xmlns="http://www.w3.org/1998/Math/MathML">9 升水,她先后用 <math xmlns="http://www.w3.org/1998/Math/MathML">2,3,2 分钟完成第 <math xmlns="http://www.w3.org/1998/Math/MathML">5,4,3 株植物的浇水,中途不需要重新灌水,在第 <math xmlns="http://www.w3.org/1998/Math/MathML">7 分钟走到第 <math xmlns="http://www.w3.org/1998/Math/MathML">2 株植物,水罐还有 <math xmlns="http://www.w3.org/1998/Math/MathML">2 升水。

因为小美先到第 <math xmlns="http://www.w3.org/1998/Math/MathML">2 株植物,她将完成整个浇水过程,她先把水罐里剩余 <math xmlns="http://www.w3.org/1998/Math/MathML">2 升水浇完,然后重新灌水一次,再浇 <math xmlns="http://www.w3.org/1998/Math/MathML">1 升水,完成整个浇水,花费 <math xmlns="http://www.w3.org/1998/Math/MathML">8 分钟。

小珅浇水总共花了 <math xmlns="http://www.w3.org/1998/Math/MathML">37 分钟,小美浇水总共花了 <math xmlns="http://www.w3.org/1998/Math/MathML">15 分钟。要等两人都完成浇水,答案是 <math xmlns="http://www.w3.org/1998/Math/MathML">37 分钟。

<math xmlns="http://www.w3.org/1998/Math/MathML">50% 数据:答案不超过 <math xmlns="http://www.w3.org/1998/Math/MathML">106

<math xmlns="http://www.w3.org/1998/Math/MathML">100% 数据:<math xmlns="http://www.w3.org/1998/Math/MathML">1n105,1wi,T106,1A,B109

来源

模拟