# Google KickStart Round E Problem 2

I feel like I am missing some corner case but I can’t think of anything else.

// Author : Epsilon573
// If it works, don’t touch it.

#include <bits/stdc++.h>
using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;

const ll mod = 1e9+7;
const ld eps = 1e-9 ;
const ll maxn = 1e5+1;
const ll inf = LLONG_MAX;
const ll minf = LLONG_MIN;

#define mp make_pair
#define pb push_back
#define endl “\n”
#define deb(x) cerr << #x << " " << x << endl

bool solve()
{
ll n,a,b,c;
cin >> n >> a >> b >> c;

``````if( a+b-c > n ) return false;
if(a==1 && b==1 && n!=1) return false;

if(n==1)
{
cout << 1 << endl;
}
else if(n==2)
{
if(a==1 && b==1) return false;

if(a==2 && b==2){
assert(c==2);
cout << "1 1" << endl;
}
else if(a==1 && b==2){
assert(c==1);
cout << "2 1" << endl;
}
else
{
assert(c==1); assert(a==2); assert(b==1);
cout << "1 2" << endl;
}
}
else
{
ll leftover = n - (a+b-c);
for(ll i=0 ; i<a-c ; ++i)
cout << 2 << " ";
for(ll i=0 ; i<c ; ++i)
cout << 3 << " ";
for(ll i=0 ; i<leftover ; ++i)
cout << 1 << " ";
for(ll i=0 ; i<b-c ; ++i)
cout << 2 << " ";
cout << endl;
}

return true;
``````

}

int main()
{
ios_base :: sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);

``````#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
freopen("error.txt","w",stderr);
#endif

ll t=1;
cin >> t;

for( ll i=1 ; i<=t ; ++i)
{
cout << "Case #" << i << ": ";
if(solve())
{
NULL;
}
else
{
cout << "IMPOSSIBLE" << endl;
}
}

return 0;
``````

}

y when a is 1 and b is 1 and n is not 1 it returns false

5 1 1 1 5
In this case a=1,b=1 and n=5 and its very much possible set of heights.

But in this case both A and B are able to see 2 buildings each. So, how can it be a possible set. And the condition is definitely true that if a=1, b=1 and n! =1 then the answer is Impossible.

Here you go
1
7 5 2 2

Output:
Case #1: 2 2 2 3 3 1 1

As you can see its best to keep the leftovers between the big towers(see editorial)
so optimal answer is 2 2 2 3 1 1 3

Well the problem here lies in the else part when n>2. To help you figure out the mistake, here is a test case
1
5 2 2 2
Your code prints - 3 3 1 1 1 but B can see 5 buildings.
A possible solution - 3 1 1 1 3

Yes, i was missing the condition when a = b = c, added that and now it works fine thanks