제출 #765998

#제출 시각아이디문제언어결과실행 시간메모리
765998FaeeStove (JOI18_stove)C++14
100 / 100
17 ms2328 KiB
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fi first
#define se second
#define endl "\n"
#define pii pair<ll,ll>
#define pb push_back
#define vi vector<ll>
#define pque priority_queue
#define pqueg priority_queue<ll,vector<ll>,greater<ll>>
#define que queue<ll>
#define FOR(m,i,n) for(int i=(m); i<=(n); i++)
#define FORM(m,i,n) for(int i=(m); i>=(n); i--)
ll n,k,ans;
ll a[100100],t[100100];
int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin >> n >> k;
	FOR(1,i,n) {
		cin >> t[i];
		if(i > 1) {
			a[i-1] = t[i] - t[i-1];
		}
	}
	ans = n;
	sort(a+1,a+n);
	if(n == k) {
		cout << n << endl;
		return 0;
	}
	FOR(1,i,n-k) {
		ans += a[i] - 1;
	}
	cout << ans << endl;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...