답안 #685675

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
685675 2023-01-24T19:19:46 Z Bliznetc Stove (JOI18_stove) C++17
100 / 100
46 ms 6416 KB
#include <bits/stdc++.h>

#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-O3")
#pragma GCC target("avx2")

using namespace std;

#define pb push_back
#define sz size()
#define all(x) x.begin(), x.end()
#define F first
#define S second

typedef pair < int, int > pii;
typedef vector < int >  vi;
typedef vector < vi >  vvi;


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

    multiset <int> s;
    for (int i = 2; i <= n; i++) {
        int diff = a[i] - a[i - 1];
        s.insert(diff - 1);
    }

    k--;
    while (s.sz > 0 && k > 0) {
        s.erase(--s.end());
        k--;
    }

    int ans = 0;
    for (auto i : s) {
//        cout << i << " ";
        ans += i;
    }
    ans += n;
    cout << ans;
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int t = 1;
//    cin >> t;
    while (t--) {
        solve();
        cout << "\n";
    }
}

# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 316 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 316 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 316 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 316 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 460 KB Output is correct
11 Correct 1 ms 460 KB Output is correct
12 Correct 2 ms 468 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 2 ms 468 KB Output is correct
15 Correct 2 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 316 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 316 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 460 KB Output is correct
11 Correct 1 ms 460 KB Output is correct
12 Correct 2 ms 468 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 2 ms 468 KB Output is correct
15 Correct 2 ms 468 KB Output is correct
16 Correct 39 ms 6336 KB Output is correct
17 Correct 43 ms 6416 KB Output is correct
18 Correct 39 ms 6352 KB Output is correct
19 Correct 46 ms 6304 KB Output is correct
20 Correct 38 ms 6264 KB Output is correct
21 Correct 40 ms 6272 KB Output is correct
22 Correct 41 ms 6344 KB Output is correct
23 Correct 36 ms 6348 KB Output is correct
24 Correct 36 ms 6312 KB Output is correct