Submission #828743

# Submission time Handle Problem Language Result Execution time Memory
828743 2023-08-17T14:53:07 Z ajay Stove (JOI18_stove) C++14
100 / 100
24 ms 2332 KB
/* Ajay Jadhav */

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <deque>
#include <vector>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <ctime>
#include <string.h>
#include <climits>
#include <cstring>
#include <numeric>
using namespace std;

#define ll long long
#define pb push_back
#define pii pair<int, int>
#define vi vector<int>
#define vvi vector<vi>
#define vii vector<pii>
#define mi map<int, int>
#define mii map<pii, int>
#define all(a) (a).begin(), (a).end()
#define x first
#define y second
#define sz(x) (int)x.size()
#define hell 1000000007
#define rep(i, a, b) for (int i = a; i < b; i++)
#define endl '\n'

void solve()
{
    int n, k;
    ll ans = 0;
    cin >> n >> k;
    vi a(n);
    rep(i, 0, n)
    {
        cin >> a[i];
        ans++;
    }
    int blobs = 1;
    sort(all(a));
    rep(i, 1, sz(a))
    {
        if (a[i] - 1 != a[i - 1])
        {
            blobs++;
        }
    }
    vi ranges;
    
    rep(i, 1, n)
    {
        int d = a[i] - a[i - 1] - 1;
        if (d > 0)
        {
            ranges.pb(d);
        }
    }

    sort(all(ranges));
    int index = 0;
    int need = (blobs - k);
    // if (need > sz(ranges))
    // {
    //     cout<<a[n - 1] - a[0] + 1<<endl;
    //     return;
    // }
    while (need-- > 0)
    {
        ans += ranges[index++];
        k++;
    }

    cout << ans << endl;
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
    // cin>>t;
    while (t--)
    {
        solve();
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 260 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 260 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 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 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 260 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 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 364 KB Output is correct
16 Correct 17 ms 2240 KB Output is correct
17 Correct 21 ms 2312 KB Output is correct
18 Correct 16 ms 2248 KB Output is correct
19 Correct 24 ms 2332 KB Output is correct
20 Correct 17 ms 2308 KB Output is correct
21 Correct 24 ms 2236 KB Output is correct
22 Correct 17 ms 2256 KB Output is correct
23 Correct 16 ms 2252 KB Output is correct
24 Correct 16 ms 2256 KB Output is correct