Submission #945396

# Submission time Handle Problem Language Result Execution time Memory
945396 2024-03-13T17:37:07 Z KasymK Stove (JOI18_stove) C++17
100 / 100
38 ms 1472 KB
#include "bits/stdc++.h"
using namespace std;

int main(){
    int n, k;
    cin >> n >> k;
    vector<int> v(n);
    for(int &i : v)
        cin >> i;
    if(k == 1){
        cout << v.back() + 1 - v.front() << "\n";
        return 0;
    }
    // int div = ceil(n/2);
    // biz aralaryny yakynlasdyrjak bolyas
    int ans = v.back() + 1 - v.front();
    vector<int> tap;
    for(int i = 0; i < n - 1; ++i){
        int diff = abs(v[i + 1] - v[i]);
        tap.push_back(diff);
    }
    k--;
    sort(tap.rbegin(), tap.rend());
    for(int i = 1; i <= k; ++i){
        ans -= tap[i - 1];
        ans++;
    }
    // ans += k;
    cout << ans << "\n";
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 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
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 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 2 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 600 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 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 2 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 600 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 34 ms 1460 KB Output is correct
17 Correct 33 ms 1240 KB Output is correct
18 Correct 33 ms 1472 KB Output is correct
19 Correct 34 ms 1240 KB Output is correct
20 Correct 38 ms 1236 KB Output is correct
21 Correct 34 ms 1228 KB Output is correct
22 Correct 34 ms 1240 KB Output is correct
23 Correct 34 ms 1232 KB Output is correct
24 Correct 35 ms 1240 KB Output is correct