# Fun game using Stacks Problem Code: TAW221A2

Here’s the problem : “Emma plays a game where she piles up two stacks using cuboids varying in height. Emma’s sister belma removes one or more cuboids at the top of the two stacks such that their height remains the same. Find the maximum possible height of the two stacks such that all of the stacks are exactly the same height and return the height. if theres no possibility print “Not possible”.”

I tried a stack based solution which seems to be correct but it giving me wrong answer can anyone help me with my code.

``````cin >> n >> m;
a = 0;
b = 0;
stack<lli>sta, stb;
bool flag = false;
for(lli i=0; i<n; i++){
cin >> k;
a += k;
sta.push(k);
}

for(lli i=0; i<m; i++){
cin >> k;
b += k;
stb.push(k);
}
while(!sta.empty() && !stb.empty()){
if(a == b){
flag = true;
break;
}
if(a > b){
a -= sta.top();
sta.pop();
}
if(b>a){
b -= stb.top();
stb.pop();
}
}

if(flag){
cout << a ;
}
else{
cout << "Not possible";
}``````

the problem’s output files are incorrect
lets look at one accepted submission
let us consider the tc-
4 4
2 1 1 3
1 1 2 3
let us consider 2 cases of output-

1. we have to remove atleast 1 cuboid from the top
expected ans in the case=4 (we remove 3 from both)
2. we may or may not remove a cuboid from the top
expected ans in the case=7(we dont have to remove any)

but the accepted output is 2
its best to ignore such problems

1 Like

Thank’s for the clarification I was really demotivated during the contest that I can’t solve such an easy question. I was tilted and didn’t tried other problems. Problems like this should be reviewed before putting in contest.