I've attempted to solve a coding contest out of curiosity. Out there, there's one of the problems which couldn't pass all the test cases for my solution. Could there be any improvement in my solution that you would suggest that might help? TIA. The problem along with my solution is stated down below.
There are N rows of Jackets & M rows of Hoodies in a mall. An individual wants to buy a jacket and a hoodie such that his coolness level is maximum. Each jacket and hoodie has a coolness value. The coolness value of the i-th jacket is the number of jackets whose price is less than the i-th jacket. The coolness value of the i-th hoodie is the number of hoodies whose price is less than the i-th hoodie. For example, if there are 4 jackets with price 4,5,2 and 3 respectively. The coolness value of the 1st jacket(whose price is 4) is 2 as only 2 jackets(3rd and 4th jacket) have price less than the 1st one.
Now, he has a limited amount of money(C tk to be exact). Help him to buy a jacket and a hoodie with the amount of money he has got such that his coolness level is maximum.
Input:
The first line of input is three integers N,M, and C, denoting the number of jackets, the number of hoodies, and the amount of money he has respectively. The second line contains N space-separated integers representing the price of the N jackets. The i-th integer ai denotes to the price of the i-th jacket. The third line contains M space-separated integers representing the price of the M hoodies. The i-th integer bi denotes to the price of the i-th hoodie. All the values of a[i] and b[i] are distinct.
The Constraints:
1 ≤ N,M ≤ 10^5,
1 ≤ C ≤ 10^7,
1 ≤ a[i],b[i] ≤ 10^7
The Output:
Print a single integer representing the maximum coolness value that he can obtain after buying one jacket and one hoodie with the given amount of money. If there is no possible way of buying one jacket and one hoodie with the money, print "E kemon aynabaji!!!"
Sample Input 0:
3 4 220
56 96 114
45 67 73 105
Sample Output 0:
5
Sample Output 1:
3 3 106
95 93 104
23 14 16
Sample Output 1:
E kemon aynabaji!!!
And my solution is:
#include<bits/stdc++.h>
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long N, M, C, count;
cin>>N>>M>>C;
long long a[N], b[M];
for(long long i=0; i<N; i++){
cin>>a[i];
}
for(long long i=0; i<M; i++){
cin>>b[i];
}
sort(a, a+N);
sort(b, b+M);
if(a[N-1] + b[M-1] <= C){
count = (N-1) + (M-1);
cout<<count<<endl;
}
else{
cout<<"E kemon aynabaji!!!"<<endl;
}
return 0;
}
Can anyone suggest what I could improve here to pass all the test cases? Any suggestions would be appreciated :)
Aucun commentaire:
Enregistrer un commentaire