제출 #1355772

#제출 시각아이디문제언어결과실행 시간메모리
1355772truongthaiduonglaptrinhStove (JOI18_stove)C++20
100 / 100
16 ms1212 KiB
// duonglaptrinh

# include <bits/stdc++.h>
using namespace std;

const int N = 1e5+5;

bool find_Max(int &ans, int x) {
    // cout<<x<<"\n";
    if(x == -1) {
        return 0;
    }
    ans = min(ans, x);
    return 1;
}

int n, k;
int a[N], b[N];

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    if(fopen("nhap.inp", "r")) {
        freopen("nhap.inp", "r", stdin);
        freopen("nhap.out", "w", stdout);
    }

    cin>>n>>k;
    for(int i = 1; i <= n; i++) {
        cin>>a[i];
    }

    sort(a + 1, a + 1 + n);

    for(int i = 1; i < n; i++) {
        b[i] = (a[i + 1] - a[i] - 1);
    }

    sort(b + 1, b + n, greater<>());

    int ans = a[n] - a[1] + 1;

    for(int i = 1; i <= min(n - 1, k - 1); i++) {
        ans -= b[i];
    }

    cout<<ans;

    return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

stove.cpp: In function 'int main()':
stove.cpp:26:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |         freopen("nhap.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
stove.cpp:27:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |         freopen("nhap.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…