๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
Algorithm ๐Ÿง‘๐Ÿป‍๐Ÿ’ป/๋ฐฑ์ค€(BOJ)

[๋ฐฑ์ค€,c++] 10818๋ฒˆ - ์ตœ์†Œ, ์ตœ๋Œ€

by dkswnkk 2021. 10. 24.

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

 

10818๋ฒˆ: ์ตœ์†Œ, ์ตœ๋Œ€

์ฒซ์งธ ์ค„์— ์ •์ˆ˜์˜ ๊ฐœ์ˆ˜ N (1 ≤ N ≤ 1,000,000)์ด ์ฃผ์–ด์ง„๋‹ค. ๋‘˜์งธ ์ค„์—๋Š” N๊ฐœ์˜ ์ •์ˆ˜๋ฅผ ๊ณต๋ฐฑ์œผ๋กœ ๊ตฌ๋ถ„ํ•ด์„œ ์ฃผ์–ด์ง„๋‹ค. ๋ชจ๋“  ์ •์ˆ˜๋Š” -1,000,000๋ณด๋‹ค ํฌ๊ฑฐ๋‚˜ ๊ฐ™๊ณ , 1,000,000๋ณด๋‹ค ์ž‘๊ฑฐ๋‚˜ ๊ฐ™์€ ์ •์ˆ˜์ด๋‹ค.

www.acmicpc.net

1๋ฒˆํ’€์ด

#include <iostream>
#include <vector>
#include <queue>
using namespace std;

int main() {

    int N;
    cin >> N;
    priority_queue<int, vector<int>, greater<int>>pq1; //์ž‘์€ ์ˆœ์„œ๋Œ€๋กœ
    priority_queue<int, vector<int>,less<int>>pq2; //ํฐ ์ˆœ์„œ๋Œ€๋กœ

    for (int i = 0; i < N; i++) {
        int number;
        cin >> number;
        pq1.push(number);
        pq2.push(number);
    }
    cout << pq1.top() <<"\n"<< pq2.top();


}

2๋ฒˆํ’€์ด

#include <iostream>
#include<vector>
using namespace std;

int main() {
    int N;
    cin >> N;
    vector<int> v;

    for (int i = 0; i < N; i++) {
        int number;
        cin >> number;
        v.push_back(number);
    }
    int max = v[0];
    int min = v[0];
    for (int i = 0; i < N; i++) {
        if (max <= v[i]) max = v[i];
        if (min >= v[i]) min = v[i];
    }
    cout << min << " " << max;

}

 

๋Œ“๊ธ€