1 solutions

  • 0
    @ 2026-11-14 11:36:55

    C++ :

    #include <bits/stdc++.h>
    #define N 100005
    using namespace std;
    int a[N];
    
    int main(){
    	int n,k,mx = -INT_MAX,mi = INT_MAX;
    	cin >> n >> k;
    	
    	for (int i = 1;i<=n;i++){
    		cin >> a[i];
    		mx = max(mx ,a[i]);
    		mi = min(mi, a[i]);
    	}
    	
    	for (int i = 1;i<=n;i++){
    		if (a[i] >k) a[i] = mx;
    		else if (a[i] <k) a[i] = mi;
    		
    		cout << a[i] << " " ;
    	}
    	return 0;
    }
    
    • 1

    Information

    ID
    150
    Time
    1000ms
    Memory
    256MiB
    Difficulty
    (None)
    Tags
    # Submissions
    0
    Accepted
    0
    Uploaded By