#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
using namespace std;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, k; // 온도의 개수, 편안하게 느낀 횟수
    cin >>n >>k;
    vector<double> a(n); // 은수가 기록한 원본 온도 리스트
    vector<double> b; // 중복을 제거하고 정렬할 온도 후보 리스트
    for(int i=0; i<n; i++) {
        cin >> a[i];
        b.push_back(a[i]);}
    sort(b.begin(), b.end()); // 후보 온도들을 오름차순 정렬
    b.erase(unique(b.begin(), b.end()), b.end());
    for(size_t i=0; i<b.size()-1; i++) {
        double low = b[i]; //구간의 최소 온도
        double high = b[i+1]; //구간의 최대 온도
        double c = (low + high) / 2.0; //검사할 가로선 (두 온도의 중간값)
        int cnt = 0; //가로선과 그래프가 만나는 횟수 세기
        for(int j=0; j<n-1; j++){
            if((a[j]<c && c<a[j+1]) || (a[j+1]<c && c<a[j])){
                cnt++;
            }}
        if(cnt == k) {
            cout << fixed << setprecision(1);
            cout << low << " " << high << "\n";
            return 0;
        }
    }
    return 0;
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: