답안 #684053

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
684053 2023-01-20T08:22:16 Z vjudge1 Stove (JOI18_stove) C++14
0 / 100
1 ms 212 KB
#include <bits/stdc++.h>
using namespace std;

#define F first
#define S second
#define pb push_back
#define all(a) a.begin(), a.end()

typedef long long ll;
typedef pair<int, int> ii;

const int N = 1e5 + 5;
const int mod = 1e9 + 7;
int n, k;
ll res, a[N], b[N];

void solve()
{
    cin >> n >> k;
    for(int i = 1; i <= n; i++)
        cin >> a[i];
    sort(a + 1, a + 1 + n);
    res = a[n];
    for(int i = 1; i < n; i++)
        b[i] = a[i + 1] - a[i] - 1;
    sort(b + 1, b + n, greater<ll>());
    for(int i = 1; i < k; i++)
        res -= b[i];
    cout << res;
}

signed main()
{
    cin.tie(0)->sync_with_stdio(0);
    int t = 1;
    // cin >> t;
    while(t--) solve();
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -