답안 #548836

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
548836 2022-04-14T13:01:37 Z Kipras Stove (JOI18_stove) C++17
100 / 100
46 ms 2636 KB
#include <bits/stdc++.h>

typedef long long ll;

using namespace std;

int main()
{

    ios_base::sync_with_stdio();cin.tie(nullptr);

    ll n, k;
    cin>>n>>k;

    vector<ll> a;

    for(int i = 0; i < n; i++){
        ll aa;
        cin>>aa;
        a.push_back(aa);
    }

    vector<ll> s;

    for(int i = 0; i < n-1; i++){
        s.push_back(a[i+1]-a[i]-1);
    }

    ll all=a[n-1]+1-a[0];

    if(k>=n)cout<<n;
    else{

        sort(s.begin(), s.end());
        reverse(s.begin(), s.end());

        for(int i = 0; i < k-1; i++){
                //cout<<s[i]<<endl;
                all-=s[i];
        }

        cout<<all;

    }

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 2 ms 340 KB Output is correct
12 Correct 2 ms 332 KB Output is correct
13 Correct 2 ms 340 KB Output is correct
14 Correct 2 ms 340 KB Output is correct
15 Correct 2 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 2 ms 340 KB Output is correct
12 Correct 2 ms 332 KB Output is correct
13 Correct 2 ms 340 KB Output is correct
14 Correct 2 ms 340 KB Output is correct
15 Correct 2 ms 340 KB Output is correct
16 Correct 42 ms 2576 KB Output is correct
17 Correct 45 ms 2636 KB Output is correct
18 Correct 42 ms 2584 KB Output is correct
19 Correct 45 ms 2532 KB Output is correct
20 Correct 46 ms 2580 KB Output is correct
21 Correct 43 ms 2568 KB Output is correct
22 Correct 42 ms 2544 KB Output is correct
23 Correct 44 ms 2580 KB Output is correct
24 Correct 44 ms 2500 KB Output is correct