Company: Eternal_26july

Difficulty: medium

Problem Statement

Power-Constrained Production A factory has n machines. You are given a fixed total power budget maxPower . Machine i (using 0-based indexing) works as follows: Switching it on consumes exactly p[i] units of power. If switched on, it produces q[i] units of quantity. A machine is either switched fully on or left off — you cannot switch a machine on partially, and a machine that is off consumes no power and produces nothing. Choose a subset of the machines to switch on so that the total power consumed does not exceed maxPower , and the total quantity produced is as large as possible . Report that maximum total quantity. You may switch on no machines at all (producing a total quantity of 0 ). Input Format The first line contains two integers n and maxPower . The second line contains n integers p[0], p[1], …, p[n-1] — the power each machine consumes. The third line contains n integers q[0], q[1], …, q[n-1] — the quantity each machine produces. Output Format Print a single integer: the maxim

More Eternal_26july OA questionsInterview experiences