Skip to content

Commit 1b01a73

Browse files
authored
[BOJ] 13164 행복 유치원 (G5)
1 parent 34087dc commit 1b01a73

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

박예진/9주차/260225.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//https://www.acmicpc.net/problem/13164
2+
3+
#include <iostream>
4+
#include <vector>
5+
#include <algorithm>
6+
using namespace std;
7+
8+
int N, K;
9+
int arr[300001];
10+
vector<int> v;
11+
12+
int main(){
13+
ios_base::sync_with_stdio(false);
14+
cin.tie(NULL); cout.tie(NULL);
15+
16+
cin >> N >> K;
17+
cin >> arr[0];
18+
for(int i = 1; i < N; i++){
19+
cin >> arr[i];
20+
v.push_back(arr[i] - arr[i - 1]);
21+
}
22+
sort(v.begin(), v.end());
23+
24+
int sum = 0;
25+
for(int i = 0; i < N - K; i++){
26+
sum += v[i];
27+
}
28+
cout << sum;
29+
30+
return 0;
31+
}

0 commit comments

Comments
 (0)