万紫千红

B4066 [GESP202412 三级] 数字替换

gaosihao @ 2024-12-15 19:14:56

#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll n,k,a[10005],maxx,minn;
int main(){
    cin>>n>>k;
    cin>>a[1];
    maxx=a[1];
    minn=a[1];
    for(int i=2;i<=n;i++)
    {
        cin>>a[i];
        if(a[i]>maxx){
            maxx=a[i];
        }
        if(a[i]<minn){
            minn=a[i];
        }
    }
    for(int i=1;i<=n;i++){
        if(a[i]>k){
            a[i]=maxx;
        }else if(a[i]<k){
            a[i]=minn;
        }
    }
    for(int i=1;i<=n;i++){
        cout<<a[i]<<' ';
    }
    return 0;
}

by XURUIFAN @ 2024-12-15 19:25:09

1 \le n \le 10^5

by yunchen_ @ 2024-12-15 19:25:17

a开到100005


by XURUIFAN @ 2024-12-15 19:26:42


by 天使宝贝 @ 2024-12-15 19:30:38

数组开小了。。。


by gaosihao @ 2024-12-20 20:31:02

好的,谢谢各位大佬


|