# FIR123 EDITORIAL

BOB THE BUILDER
Tester: Prasoon Jain
Editorialist: Pratima Singh

SIMPLE, EASY

# PREREQUISITES:

Maths, Observation, Implementation

# PROBLEM:

Given two incomplete walls w1 and w2. These two walls will be having height w1 and w2 before we start to work upon them. There are k number of bricks available and we need to spend all of these bricks in building both the walls such that height w1 is strictly greater than w2. Adding one brick increase the height of wall by one. We only need to tell the number of possibilities such that :-

• All bricks are used, and w1 > w2.

# EXPLANATION:

To satisfy the given condition, w1>w2, just count the number of cases such that dividing part of k in w1 and rest part of k in w2 results in such a case such that w1>w2. Since adding one brick results in increase of height by one, we will first add k to w1 and then keep on decrementing the value of w1 by one and simultaneously incrementing the value of w2 by one only until it satisfies the condition- w1>w2. In each step keep on incrementing the answer by one and print it when it becomes equal to k+1. Note that the maximum possible answer is k+1.

# SOLUTION:

Editorialist's Solution
``````#include <iostream>
#define ll long long int
using namespace std;

int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll t;
cin>>t;
while(t--){
ll w1, w2, k;
ll ans=0;
cin>>w1>>w2>>k;
w1 = w1+k;
while(w1>w2){
w1--;
w2++;
ans++;
if(ans==k+1){
break;
}
}
cout<<ans<<'\n';

}

return 0;
}
``````