답안 #975290

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
975290 2024-05-04T17:05:56 Z ShaShi Stove (JOI18_stove) C++17
100 / 100
21 ms 4828 KB
#include <bits/stdc++.h>
#define int long long
#define pii pair<int, int>
#define all(x) x.begin(), x.end()
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define kill(x) cout << x << endl, exit(0);
#define endl "\n"

 
using namespace std;
typedef long long ll;
typedef long double ld;
 

const int MAXN = (int)1e6 + 7;
const int MOD = (int)1e9 + 7;
const ll INF = (ll)1e18 + 7;
 

int n, m, t, q, tmp, tmp2, tmp3, tmp4, ans, k, u, v, w, flag;
int arr[MAXN];
vector<int> vec;


int32_t main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    cin >> n >> k;

    for (int i=1; i<=n; i++) cin >> arr[i];

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

    ans = arr[n]-arr[1]+1;


    for (int i=2; i<=n; i++) vec.pb(arr[i]-arr[i-1]);
    sort(all(vec), greater<int>());

    for (int i=1; i<k; i++) ans -= vec[i-1]-1;

    cout << ans << endl;

    

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 600 KB Output is correct
3 Correct 0 ms 472 KB Output is correct
4 Correct 1 ms 600 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 600 KB Output is correct
3 Correct 0 ms 472 KB Output is correct
4 Correct 1 ms 600 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 504 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 600 KB Output is correct
3 Correct 0 ms 472 KB Output is correct
4 Correct 1 ms 600 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 504 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 16 ms 4824 KB Output is correct
17 Correct 16 ms 4824 KB Output is correct
18 Correct 16 ms 4828 KB Output is correct
19 Correct 16 ms 4816 KB Output is correct
20 Correct 16 ms 4828 KB Output is correct
21 Correct 19 ms 4700 KB Output is correct
22 Correct 16 ms 4828 KB Output is correct
23 Correct 17 ms 4808 KB Output is correct
24 Correct 21 ms 4720 KB Output is correct