Submission #1090162

#TimeUsernameProblemLanguageResultExecution timeMemory
1090162HienTDStove (JOI18_stove)C++14
100 / 100
16 ms1968 KiB
#include <bits/stdc++.h>
using namespace std;

//#define LOCAL

#define          	fi  first
#define             se  second
#define           TIME  (1.0 * clock() / CLOCKS_PER_SEC)
#define         ALL(v)  (v).begin(), (v).end()
#define  		BIT(x)  (1LL << (x))
#define 	MASK(x, i)  (((x) >> (i)) & 1)
#define   FOR(i, a, b)  for(int i = (a), _b = (b); i <= _b; ++ i)
#define  FORD(i, b, a)  for(int i = (b), _a = (a); i >= _a; -- i)

const string NAME = "BAITAP";

const long long INF = 1e18;
const int inf = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const int mod = 998244353;

const int mxN = 1e5 + 5;

int N, K;
vector<int> d(mxN);

void init(void){
	cin >> N >> K;
	int a, b;
	FOR(i, 1, N){
		cin >> b;
		if(i > 1) d[i - 1] = b - a - 1;
		a = b;
	}
}

void process(void){
	sort(d.begin() + 1, d.begin() + N);
	int ans = N;
	FOR(i, 1, N - K) ans += d[i];
	cout << ans;
}

signed main(void){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	#ifdef LOCAL
		freopen((NAME + ".INP").c_str(), "r", stdin);
		freopen((NAME + ".OUT").c_str(), "w", stdout);
	#endif // I/O

	init();
	process();
	cerr << "\nTime elapsed: " << TIME << "s.\n";
}

#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...