#include #include struct segment { int A; int B; int C; int D; int E; int cap; public: int calc() { int total = 0; int up = A; int down = D; int newB = B; int newE = E; int newC = C; total += std::min(down, E); newE -= std::min(down, E); down -= std::min(down, E); total += std::min(up, B); newB -= std::min(up, B); up -= std::min(up, B); if(up != 0) { if(newE != 0 && newC != 0) { int transfer = std::min(newC, up); newC -= transfer; up -= transfer; total += std::min(transfer, newE); newE -= std::min(transfer, newE); } } if(down != 0) { if(newB != 0 && newC != 0) { int transfer = std::min(newC, down); newC -= transfer; down -= transfer; total += std::min(transfer, newB); newB -= std::min(transfer, newB); } } this->cap = total; //std::cout << "total is: " << total << std::endl; return total; } }; int main() { int num; if(scanf("%d", &num) != 1) std::cout << "what"<< std::endl; std::vector segs; for(int i = 0; i < num; i++) { int A,B,C,D,E; if(scanf("%d %d %d %d %d", &A, &B, &C, &D, &E) != 5) std::cout<<"what"<