#include
using namespace std;
int main(){int max_high = 0;int step,w1,w2,h1,h2;cin >> step>> w1>> w2>> h1>> h2;int vOfA= w1*w1*h1 , vOfB = w2*w2*h2 ;bool out = false;int nowV = 0 , k = 0;
for(int i = 1; i <= step ; i++){//cout << k;
int b;
cin >> b;
nowV += b;
if(out == false && nowV <= vOfA){k = b/(w1*w1);if(k > max_high){max_high = k;}k = 0;
}else if (out == true && nowV <= vOfA + vOfB){k = b/(w2*w2);if(k > max_high){max_high = k;}k = 0;}else if(out == false && (nowV > vOfA && (nowV <= vOfA+vOfB) ) ){int g = nowV - vOfA;k = g / (w2*w2);k += (b-g) / (w1*w1);if(k > max_high){max_high = k;}k = 0 ;out = true;}else if (out == true||b < nowV){int g = nowV - (vOfA + vOfB);k = (b - g) / (w2*w2);if(k > max_high){max_high = k;}k = 0 ;}else{max_high = h1 + h2;}}cout << max_high;}
else if (out == true||b < nowV)
這行有誤
out==true在這裡才執行代表裝超過了,且是從第二杯開始裝。
b<nowV在這裡成立時代表還沒到第二杯,但是裝超過了,且它是第二個體積。所以要先算第一杯剩多少高度。