답안 #671008

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
671008 2022-12-11T16:17:47 Z Arixcrest Stove (JOI18_stove) C++17
100 / 100
19 ms 2264 KB
#include <bits/stdc++.h>
using namespace std;
 
using ll =  long long;
#define pi pair<int,int> 
#define rep(x,start,end) for(auto x=(start)-((start)>(end));x!=(end)-((start)>(end));((start)<(end)?x++:x--))
#define getunique(v) {sort(v.begin(), v.end()); v.erase(unique(v.begin(), v.end()), v.end());}
const ll INF = -1;
const int mx = 1e5+5;
const int modulo =1e9+7;
mt19937 mt;
void solve(){
	int n,k;
	cin>>n>>k;
	vector<int> arr(n);
	rep(x,0,n) cin>>arr[x];
	vector<int> distances;
	ll ans = n;
	rep(x,1,n){
		distances.push_back(arr[x]-arr[x-1]-1);
	}
	sort(distances.begin(),distances.end(),greater<int>());
	while(n>k){
		// cout<<n<<" "<<k<<'\n';
		ans+=distances.back();
		distances.pop_back();
		n--;
	}
	cout<<ans<<"\n";

}
 
 
 
 
 
 
 
 
int main(){
	ios_base ::sync_with_stdio(0), cin.tie(0);
	clock_t start, end;
	start = clock();
	int t = 1;
	// cin >> t;
	// int x=0;
	while (t-->0)
	{
        //cout<<"Case #"<<x<<": ";
		solve();
        // x++;
	}
	end = clock();
	cerr << double(end - start) / double(CLOCKS_PER_SEC) << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 320 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 320 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 2 ms 340 KB Output is correct
15 Correct 1 ms 372 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 320 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 2 ms 340 KB Output is correct
15 Correct 1 ms 372 KB Output is correct
16 Correct 17 ms 2248 KB Output is correct
17 Correct 16 ms 2256 KB Output is correct
18 Correct 17 ms 2252 KB Output is correct
19 Correct 17 ms 2236 KB Output is correct
20 Correct 19 ms 2264 KB Output is correct
21 Correct 19 ms 2264 KB Output is correct
22 Correct 18 ms 2260 KB Output is correct
23 Correct 16 ms 2248 KB Output is correct
24 Correct 17 ms 2264 KB Output is correct