July 2021

B - Iron Man's Server

Solution

\[\]

Implementation

#include <iostream>

using namespace std;

int main() {
    int t, n, m, x, y, i;
    cin>>t;
    
    int a[10000];
    
    int min_ele, max_ele;
    
    while (t--) {
        cin>>n>>m>>x>>y;
        
        for (i = 0; i < m; i++)
            cin>>a[i];
        
        min_ele = a[0];
        max_ele = a[0];
        
        //Find the minimum and maximum element of the array
        for (i = 0; i < m; i++) {
            if (a[i] < min_ele)
                min_ele = a[i];
            if (a[i] > max_ele)
                max_ele = a[i];
        }
        
        if (min_ele < x || max_ele > y)
            cout<<"NO\n";
        else if (n-m == 0 && min_ele == x && max_ele == y)
            cout<<"YES\n";
        else if (n-m == 1 && (min_ele == x || max_ele == y))
            cout<<"YES\n";
        else if (n-m >= 2)
            cout<<"YES\n";
        else
            cout<<"NO\n";
    }
    
    return 0;
}
\[\]

Contest Material