Submission #1049749

# Submission time Handle Problem Language Result Execution time Memory
1049749 2024-08-09T04:43:17 Z vjudge1 Stove (JOI18_stove) C++17
100 / 100
20 ms 3024 KB
#include <bits/stdc++.h>

#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,lzcnt,mmx,abm,avx,avx2,fma")
#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math,inline")

using namespace std;

#define speed ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define vc vector
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ll long long
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define int ll

const int N = 1e5 + 5;
const int M = 1e5 + 5;
const int mod = 1e9 + 7;
const int block = 500;

int n, k, a[N];

void solve() {
	cin >> n >> k;
    ll ans = n;
    for ( int i = 1; i <= n; i++ ) {
        cin >> a[i];
    }
    vc <int> save, dist;
    sort(a+1,a+n+1);
    for ( int i = 2; i <= n; i++ ) {
        if ( a[i] - a[i-1] <= 1 ) continue;
        dist.pb(a[i]-a[i-1]-1);
        save.pb(a[i]);
    }
    save.pb(a[n]);
    if ( sz(save) <= k ) {
        cout << ans;
        return;
    }
    sort(all(dist));
    int k2 = sz(save) - k;
    for ( int i = 0; i < k2; i++ ) {
        ans += dist[i];
    }
    cout << ans;
}

signed main() {
	speed;
	int tt;
	//cin >> tt;
    tt = 1;
	while ( tt-- ) {
		solve();
		cout << '\n';
	}
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 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 344 KB Output is correct
2 Correct 0 ms 344 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 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 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 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 464 KB Output is correct
16 Correct 13 ms 3020 KB Output is correct
17 Correct 15 ms 3016 KB Output is correct
18 Correct 15 ms 3024 KB Output is correct
19 Correct 13 ms 3024 KB Output is correct
20 Correct 13 ms 3020 KB Output is correct
21 Correct 14 ms 3020 KB Output is correct
22 Correct 20 ms 2864 KB Output is correct
23 Correct 13 ms 3016 KB Output is correct
24 Correct 13 ms 3024 KB Output is correct