Array Sorting

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
closed account (4z86RXSz)
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
@iamdad3
it doesn't give AC.
still getting WA
closed account (4z86RXSz)
try this combat[j]<chef[i] in if statement
still giving WA
Topic archived. No new replies allowed.