Jul 28, 2018 at 6:54am UTC
Hi can you help me where Am I going wrong in this code i am getting 30 pts and WA for 2 test cases;
https://www.codechef.com/LOCJUL18/problems/CMK
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
#include <bits/stdc++.h>
using namespace std;
int main() {
int test;
int n;
int k;
cin >> test;
while (test--) {
cin >> n >> k;
int chef[n];
int combat[n];
for (int i = 0; i < n; ++i) {
cin >> combat[i];
}
sort(combat, combat + n);
for (int i = 0; i < n; ++i) {
cin >> chef[i];
}
sort(chef, chef + n);
int cnt = 0;
bool flag = false ;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
if (combat[i] < chef[j]) {
cnt++;
break ;
}
}
if (cnt >= k) {
flag = true ;
break ;
}
}
if (flag == true ) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
}
return 0;
}
Last edited on Jul 28, 2018 at 6:54am UTC
Jul 28, 2018 at 7:23am UTC
I did this question change the value of combat[i] and chef[j]to INT_MAX after using them so they are not repeatedly used also instead of ctr++ do k-- and break when k==0
Jul 28, 2018 at 3:16pm UTC
@iamdad3
it doesn't give AC.
still getting WA
Jul 28, 2018 at 6:05pm UTC
try this combat[j]<chef[i] in if statement