Question: BNY Mellon , Recent Online Assessment (21st August 2023) | Server Investment | Minimum Processing Time
6
Entering edit mode

10
Entering edit mode

// server investment

 

#include<bits/stdc++.h>
using namespace std;
 
int main() {
   
    int n;cin >> n;
    vector<int> num_servers(n), money(n), sell(n), upgrade(n);
    for(int i=0;i<n;i++) cin >> num_servers[i];
    for(int i=0;i<n;i++) cin >> money[i];
    for(int i=0;i<n;i++) cin >> sell[i];
    for(int i=0;i<n;i++) cin >> upgrade[i];
 
    int res=0;
 
    for(int i=0;i<n;i++) {
        int lo=0, hi=num_servers[i];
        int temp=0;
        while(lo<=hi) {
            int mid=lo+(hi-lo)/2;
 
            if(mid*upgrade[i]<=money[i]+sell[i]*(num_servers[i]-mid)) {
                temp=mid;
                lo=mid+1;
            }
            else hi=mid-1;
        }
        res+=temp;
    }
 
    cout << res << "\n";
 
    return 0;
}
ADD COMMENTlink 13 months ago sumeet kumar sahoo • 290
2
Entering edit mode

// approach

since ith network is independent from all other networks(means one network's value doesn't depend on other networks) we can handle it seperately.
to get the max number of towers we can upgrade in ith network, we can apply binary search on no of towers in ith network.
Bounds of binary search will be low=0, high=n. now we have to check if we can upgrade (mid) towers, to check the fesibility we will check if mid*upgrade[i] <= sell[i]*(num of remaining towers in the network)+money[i] is true. if it is true we will set it is as a possible solution and try for a higher value, if its false we will check for a lower value.

ADD COMMENTlink 13 months ago sumeet kumar sahoo • 290

Login before adding your answer.

Similar Posts
Loading Similar Posts