Read the problem statement clarification at the top of the discussion post. You are misinterpreting the question, observe the table given carefully.
Read the problem statement clarification at the top of the discussion post. You are misinterpreting the question, observe the table given carefully.
Yes I did think of a way without actually sorting. I coded it and submitted the solution, but for some reason I'm getting a few test cases wrong. Could you have a look at it?
Thanks!
#include <bits/stdc++.h>using namespace std;bool pyramid(int m, int* count){int blocks = 0;for(int i = 1000000; i > m; i--)blocks += count[i]; //counting number of blocks with side > mfor(int i = m; i > 0; i--){if(count[i] == 0)blocks--; //if for any side i(<m) the block is not present, we use one of the previous unused blockselseblocks += (count[i] - 1); //else we add the extra blocksif(blocks < 0)return false; //if we ever run out of blocks, return false
The problem can be solved simply using sorting, but I think using binary search to solve it would be much more fun and informative. What do you all think?