답안 #229486

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
229486 2020-05-04T15:37:19 Z Tehillah Stove (JOI18_stove) C++14
100 / 100
28 ms 3324 KB
#include <bits/stdc++.h>
using namespace std;

using ll = long long;

#define pb push_back
#define mkp make_pair
#define ff first
#define ss second
#define all(a) a.begin(), a.end()
#define sz(a) (int)(a.size())
#define clr(a, b) memset(a, b, sizeof(a))
#define REP(i, a, b) for(int i=(int)(a); i<(int)(b); ++i)
#define REPD(i, a, b) for(int i=(int)(a)-1; i>=(int)(b); --i)
#define FOR(it,c) for ( __typeof((c).begin()) it=(c).begin(); it!=(c).end(); it++ )

template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int N = 100005;
ll a[N];
int n, kk;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> kk;
    ll res = 0;
    REP(i, 0, n) {
    	cin >> a[i];    
    }
    res = a[n-1] - a[0] + 1;
    vector<ll> v;
    REP(i, 1, n) {
        v.pb(a[i] - a[i-1] - 1);
    }
    sort(all(v));
    reverse(all(v));
    REP(i, 0, kk-1) {
        res -= v[i];
    }
    cout << res << "\n";
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 5 ms 512 KB Output is correct
11 Correct 5 ms 512 KB Output is correct
12 Correct 5 ms 512 KB Output is correct
13 Correct 5 ms 512 KB Output is correct
14 Correct 6 ms 512 KB Output is correct
15 Correct 5 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 5 ms 512 KB Output is correct
11 Correct 5 ms 512 KB Output is correct
12 Correct 5 ms 512 KB Output is correct
13 Correct 5 ms 512 KB Output is correct
14 Correct 6 ms 512 KB Output is correct
15 Correct 5 ms 512 KB Output is correct
16 Correct 28 ms 3324 KB Output is correct
17 Correct 28 ms 3316 KB Output is correct
18 Correct 28 ms 3196 KB Output is correct
19 Correct 28 ms 3324 KB Output is correct
20 Correct 27 ms 3196 KB Output is correct
21 Correct 28 ms 3324 KB Output is correct
22 Correct 28 ms 3316 KB Output is correct
23 Correct 27 ms 3196 KB Output is correct
24 Correct 27 ms 3188 KB Output is correct