Submission #1033665

# Submission time Handle Problem Language Result Execution time Memory
1033665 2024-07-25T04:11:51 Z vjudge1 Stove (JOI18_stove) C++17
100 / 100
16 ms 2524 KB
// #pragma GCC optimize("O3,unroll-loops")
// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include <bits/stdc++.h>
#define ll long long
#define For(i,a,b) for(ll  i=(a);i<=(b);i++)
#define Ford(i,a,b) for(ll  i=(a);i>=(b);i--)
#define pb push_back
#define all(x) x.begin(), x.end()
#define fi first
#define se second
#define endl "\n"
using namespace std;
int Dx[] = {0, 1, 0, -1, -1, -1, 1, 1};
int Dy[] = {-1, 0, 1, 0, 1, -1, 1, -1};
int dx[] = {0, 1, 0, -1};
int dy[] = {-1, 0, 1, 0};
const ll inf = 1000000000000000000;
const int N = 1000;
const int block_size = 300;
const ll MOD =  1e9 + 7; /* 998244353 */
const int LG = 18;
const int K = 20;	
const int M = 1000000;
ll nph(ll k, ll x) { return ((x >> k) & 1); }

void Solve() { 
	ll n,k; cin>>n>>k; ll a[n+3];
	For(i, 1, n) cin>>a[i];
	vector<ll> v;
	For(i, 2, n) {
		v.pb(a[i] - a[i-1] - 1);
	}
	sort(v.rbegin(), v.rend());
	ll ans = a[n] + 1 - a[1];
	for(ll i = 0; i < min(k-1, (ll)v.size()); i++) ans -= v[i];
	cout << ans;
}	
int main() {
    // freopen("BETTER.INP", "r", stdin);
    // freopen("BETTER.OUT", "w", stdout);
    ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
    int t = 1;
    //cin>>t; 
    while(t--) 
    	Solve();
}
 
# 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 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 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 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 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 14 ms 2268 KB Output is correct
17 Correct 13 ms 2384 KB Output is correct
18 Correct 15 ms 2524 KB Output is correct
19 Correct 13 ms 2376 KB Output is correct
20 Correct 14 ms 2268 KB Output is correct
21 Correct 16 ms 2388 KB Output is correct
22 Correct 13 ms 2264 KB Output is correct
23 Correct 13 ms 2268 KB Output is correct
24 Correct 13 ms 2392 KB Output is correct