페이지

10818번: 최소, 최대

https://www.acmicpc.net/problem/10818


$O(n)$


#include<cstdio>
int n, a = 1e9, b = -1e9, x;
int main() {
    scanf("%d", &n);
    while (n--) {
        scanf("%d", &x);
        if (x < a) a = x;
        if (x > b) b = x;
    }
    printf("%d %d", a, b);
    return 0;
}

댓글 없음 :

댓글 쓰기