Almost nothing in today’s world runs without power. Right from the air conditioner and water heaters to phone charging and electricity. Energy has its own role to play in everything that happens. But with increasing number of homes, the power consumption increases. The number of electricity sources does not follow the same rate of increase. So it becomes very difficult to supply all sections of a place with power simultaneously. Some areas will have to face blackout, whereas other places will have proper supply. And the electricity department needs revenue every month. This paper provides an optimal solution to provide electricity to a city divided into different sections or areas, when only a limited amount of energy units are available or generated. Assuming that each grid has its own power consumption and as per that and the revenue, the approach used in the proposed work is 0/1 knapsack problem to provide energy in a smart grid such that almost all of the power is used and maximum revenue is generated. This can be done through various methods like dynamic programming, greedy approach, brute force, backtracking, etc. We also find out that which approach will give the best solution with least time complexity. © The Editor(s) (if applicable) and The Author(s), under exclusive license to Springer Nature Singapore Pte Ltd 2021.