Submission #926754

# Submission time Handle Problem Language Result Execution time Memory
926754 2024-02-13T16:41:44 Z vin Stove (JOI18_stove) C++14
100 / 100
19 ms 3636 KB
#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define mp make_pair
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>

const int INF = 2147483645;
const int maxN = (int)2e5+5;
const ll LLINF = LLONG_MAX;
const ll mod = 998244353;
//const ll mod = 1000000007;

void solv() {
	ll n, k, a;
	vector<ll> v, diff;
	cin>>n>>k;
	for (int i=0;i<n;i++){
		cin>>a;	v.pb(a);
	}
	for (int i=0;i<n-1;i++) {
		ll res = v[i+1]-v[i];
		diff.pb(res);
	}
	sort(diff.begin(), diff.end());
	ll ans = n;
	for (int i=0;i<n-k;i++) {
		ans -= 1;
		ans += diff[i];
	}
	cout<<ans<<'\n';
}

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    int t=1;
//    cin>>t;
    while (t--) solv();
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 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 0 ms 596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 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 0 ms 596 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 464 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 464 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 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 0 ms 596 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 464 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 464 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 15 ms 3544 KB Output is correct
17 Correct 16 ms 3544 KB Output is correct
18 Correct 17 ms 3636 KB Output is correct
19 Correct 15 ms 3544 KB Output is correct
20 Correct 15 ms 3544 KB Output is correct
21 Correct 15 ms 3540 KB Output is correct
22 Correct 15 ms 3540 KB Output is correct
23 Correct 19 ms 3544 KB Output is correct
24 Correct 16 ms 3552 KB Output is correct