Submission #931253

# Submission time Handle Problem Language Result Execution time Memory
931253 2024-02-21T12:51:45 Z HaciyevAlik Stove (JOI18_stove) C++14
100 / 100
18 ms 4312 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define oo 1000000000000
const ll mx=1e5+5;
int main(){
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    ll n,k,cnt=1,dif=oo; cin >> n >> k;
    vector<ll> t(n);
    vector<pair<ll,ll>> v;
    for(ll i=0;i<n;++i) {
        cin >> t[i];
    }
    for(ll i=1;i<n;++i) {
        if(t[i]==t[i-1]+1) {
            ++cnt;
        } else {
            v.push_back({dif,cnt});
            cnt=1;
            dif=t[i]-t[i-1]-1;
        }
    }
    v.push_back({dif,cnt});
    sort(v.rbegin(),v.rend());
    ll ans=0;
    for(ll i=0;i<min(k,ll(v.size()));++i) {
        ans += v[i].second;
    }
    for(ll i=k;i<ll(v.size());++i) {
        ans=ans+v[i].first+v[i].second;
    }
    cout << ans;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 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 1 ms 348 KB Output is correct
9 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 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 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 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 600 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 1 ms 600 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 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 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 600 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 1 ms 600 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 18 ms 4312 KB Output is correct
17 Correct 17 ms 4312 KB Output is correct
18 Correct 17 ms 4312 KB Output is correct
19 Correct 18 ms 4300 KB Output is correct
20 Correct 17 ms 4308 KB Output is correct
21 Correct 17 ms 4312 KB Output is correct
22 Correct 17 ms 4172 KB Output is correct
23 Correct 17 ms 4312 KB Output is correct
24 Correct 17 ms 4308 KB Output is correct