제출 #238758

#제출 시각아이디문제언어결과실행 시간메모리
238758ignaciocantaStove (JOI18_stove)C++14
100 / 100
32 ms2432 KiB
#include <bits/stdc++.h>
 
using namespace std;
 
#define forsn(i, s, n) for(int i=s;i<int(n);i++)
#define forn(i, n) forsn(i, 0, n)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define NACHO {ios::sync_with_stdio(0); cin.tie(NULL);}
 
typedef long long tint;
 
const int INF = 50000200;
const int MOD = 1e9+7;
const int N = 100001;

int dx[4] = {1,-1,0,0};
int dy[4]  = {0,0,1,-1};

bool valid(int x, int y, int n, int m){ return (0<=x && x<n && 0<=y && y<m);}

int main(){
	NACHO;
	int n, k;
	cin >> n >> k;
	vector<int> t (n);
	forn(i, n) cin >> t[i];
	vector<int> difs;
	forsn(i, 1, n) difs.push_back(t[i]-t[i-1]-1);
	sort(rall(difs));
	int tot = t.back()-t[0]+1;
	forn(i, k-1){
		tot-=difs[i];
	}
	cout << tot << "\n";
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...