Submission #1049732

# Submission time Handle Problem Language Result Execution time Memory
1049732 2024-08-09T04:31:41 Z vjudge1 Stove (JOI18_stove) C++
100 / 100
14 ms 1508 KB
#include <bits/stdc++.h>

using namespace std;
//abeke

typedef long long ll;
typedef unsigned long long ull;

#define all(x) x.begin(), x.end()
//#define sz(x) (int)x.size()
#define pb push_back
#define speed ios::sync_with_stdio( false); cin.tie(nullptr); cout.tie(0);
#define forn(i, n) for(int i = 0; i < int(n); i++)
#define eb emplace_back
#define nl '\n'
#define f first
#define s second
#define gcd __gcd
#define ins insert
const int inf = INT_MAX;
const int mod = 1e9+7;
const int N = 2e5+5;

void solve() {
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    forn (i, n) cin >> a[i];
    vector<int> v;
    int ans = a[n-1]-a[0]+1;
    for (int i = 1; i < n; i++) {
        v.pb(a[i]-a[i-1]-1);
    }
    sort(all(v));
    k--;
    for (int i = v.size()-1; i >= 0 && k > 0; i--) {
        ans -= v[i];
        k--;
    } cout << ans;
}
int main()
{
    speed;
    solve();
    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 1 ms 344 KB Output is correct
11 Correct 0 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 600 KB Output is correct
15 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 1 ms 344 KB Output is correct
11 Correct 0 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 600 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 14 ms 1504 KB Output is correct
17 Correct 11 ms 1508 KB Output is correct
18 Correct 11 ms 1504 KB Output is correct
19 Correct 12 ms 1504 KB Output is correct
20 Correct 11 ms 1504 KB Output is correct
21 Correct 11 ms 1504 KB Output is correct
22 Correct 11 ms 1500 KB Output is correct
23 Correct 11 ms 1504 KB Output is correct
24 Correct 11 ms 1504 KB Output is correct