답안 #1049725

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1049725 2024-08-09T04:28:42 Z vjudge1 Stove (JOI18_stove) C++17
100 / 100
28 ms 2356 KB
#pragma GCC optimize("O3")
#pragma GCC target("avx2")
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <time.h>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <bits/stdc++.h>

#define speed ios_base::sync_with_stdio(0), cin.tie(0)
#define TxtIO freopen("points.in","r",stdin); freopen("points.out","w",stdout);
using namespace std;
const int mod = 998244353;
#define ll long long
const int N=2e5+5;

//mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

ll binpow (ll a, ll n) {
	ll res = 1;
	while (n) {
		if (n & 1)
			res = res * a;
		a = a * a;
		n >>= 1;
	}
	return res;
}




void fcn(){
	ll n,k;
	cin>>n>>k;
	ll a[n+3];
	vector <ll> v;
	for (int i=0; i<n; i++){
		cin>>a[i];
	}
	for (int i=1; i<n; i++){
		v.push_back(a[i]-a[i-1]);
	}
	
	sort(v.begin(),v.end());
	ll ans=0;
	for (int i=0; i<n-k; i++){
		ans+=v[i];
	}
	
	ans+=k-1;
	cout<<ans+1;
	
	
	
	
	
	
}                        

int main(){
	//srand(time(0));
	//fflush(stdout);
//	freopen("bridges.in","r",stdin); freopen("bridges.out","w",stdout);
	
	
//	speed;
	ll T=1;
//	cin>>T;
	for (int i=1; i<=T; i++){
		fcn();	
	}
}




 

/*

1
2 3
4 5
6 7


*/
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 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 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 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 1 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 2 ms 348 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
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 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 1 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 2 ms 348 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 25 ms 2260 KB Output is correct
17 Correct 24 ms 2356 KB Output is correct
18 Correct 24 ms 2356 KB Output is correct
19 Correct 25 ms 2348 KB Output is correct
20 Correct 25 ms 2352 KB Output is correct
21 Correct 27 ms 2340 KB Output is correct
22 Correct 26 ms 2344 KB Output is correct
23 Correct 25 ms 2352 KB Output is correct
24 Correct 28 ms 2260 KB Output is correct