Submission #703922

# Submission time Handle Problem Language Result Execution time Memory
703922 2023-03-01T01:21:44 Z ngano_upat_na Stove (JOI18_stove) C++17
100 / 100
21 ms 3352 KB
#include "bits/stdc++.h"
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n, k;
    cin >> n >> k;
    vector<int> v(n);
    for (auto &e:v) cin >> e;
    
    vector<pair<int,int>> intervals;
    int l = v[0], r = v[0] + 1;
    int cur = v[0];
    for (int i=1; i<n; i++) {
        if (v[i] == cur+1) {
            r = v[i] + 1;  
        }   
        else {
            intervals.push_back({l,r});
            l = v[i];
            r = v[i] + 1;
        }   
        cur = v[i];
    }   
    intervals.push_back({l,r});
    int sz = intervals.size();
    int sum = 0;
    for (auto &e:intervals) {
        sum += (e.second - e.first);
    }   
    
    vector<int> gap;
    for (int i=1; i<sz; i++) {
        int dif = intervals[i].first - intervals[i - 1].second;
        gap.push_back(dif);
        sum += dif;
    }   
    sort(gap.rbegin(),gap.rend());
    for (int i=0; i<min(k-1,(int)gap.size()); i++) {
        sum -= gap[i];
    }   
    cout << sum;
}   
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 324 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 320 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 324 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 320 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 324 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 320 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 20 ms 3352 KB Output is correct
17 Correct 18 ms 3252 KB Output is correct
18 Correct 18 ms 3280 KB Output is correct
19 Correct 19 ms 3268 KB Output is correct
20 Correct 21 ms 3260 KB Output is correct
21 Correct 17 ms 3336 KB Output is correct
22 Correct 18 ms 3268 KB Output is correct
23 Correct 18 ms 3268 KB Output is correct
24 Correct 18 ms 3280 KB Output is correct