Electronics Shop | Hackerrank Solution in C++
Electronics Shop | Hackerrank Solution
It is an hackerrank problem you can find it by clicking here. Below given solution is prepared by one of the coder of our. Soultion in C++
#include<iostream>
using namespace std;
int main(){
int s,n,m,a,cost = -1; int keyboard[1001],usb[1001];
cin >> s >> n >> m; for(int i = 0; i < n; i++)cin >> keyboard[i]; for(int i = 0; i < m; i++)cin >> usb[i];
for(int i = 0; i < n; i++){ for(int j = 0; j < m; j++){ if(keyboard[i]+usb[j] <= s) cost = max(cost,keyboard[i]+usb[j]); } } cout<<cost<<endl; return 0;}
It is an hackerrank problem you can find it by clicking here.
Below given solution is prepared by one of the coder of our.
Soultion in C++
#include<iostream>
using namespace std;
int main(){
int s,n,m,a,cost = -1;
int keyboard[1001],usb[1001];
cin >> s >> n >> m;
for(int i = 0; i < n; i++)cin >> keyboard[i];
for(int i = 0; i < m; i++)cin >> usb[i];
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++){
if(keyboard[i]+usb[j] <= s)
cost = max(cost,keyboard[i]+usb[j]);
}
}
cout<<cost<<endl;
return 0;
}

Comments
Post a Comment