not all optimization problem are in p,np. some are NP hard like longest path e.t.c.
what u have to understand -
DECISION PROBLEM ARE EASIER THAN SOLVING OPTIMIZATION PROBLEM.
i.e. a function is computable only when it is decidable.
decision problem are the problem which have answer in yes or no form
see this theory and u may understand.-
we convert our optimization problem into decision problem so that it can become easy.
Take for example the Halting Problem of a Turing Machine, suppose someone asked you after how many steps the Turing Machine will halt on a given input. To answer the exact number you first have to answer whether the Turing Machine is going to halt or not. Then i may count the steps.
What we do is to convert our optimization problem to a decision problem. And if we are not able to give answer of that decision problem we cannot compute it. So, computing is harder than saying yes or no. So if the problem is undecidable then it will be also non computable.
so now u may understand where u are wrong if u can solve it in polynomial time definitely the decision problem will be solved in polynomial time.