답안 #740024

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
740024 2023-05-12T00:51:26 Z mzv Stove (JOI18_stove) C++17
0 / 100
0 ms 212 KB
#include <bits/stdc++.h>

#define ccd ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define endl '\n'

using namespace std;

/* ------------------------ hi lol ------------------------ */

string s;
ll n,k,ans,arr[100'001];
priority_queue<ll> pq;
bool done=false;

int main() {
	ccd
	cin >> n >> k;
	for (int i=1;i<=n;i++) {
		cin >> arr[i];
		if (i==1&&!done) {
			if (arr[1]!=1) {
				pq.push(arr[1]-1);
			}
			done=1;
		}
		if (i>1) {
			if (arr[i]-arr[i-1]>1) {
				pq.push(arr[i]-arr[i-1]-1);
			}
		}
	}
	ans=arr[n];
	if (n==1) {
		cout << ans-pq.top() << endl;
		return 0;
	}
	k--;
//	cout << ans << endl;
//	while (!pq.empty()) {
//		cout << pq.top() << " ";
//		pq.pop();
//	} cout << endl;
	while (k&&!pq.empty()) {
		ans-= pq.top();
		pq.pop();
		k--;
	//	cout << ans << " ";
	}
	cout << ans << endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -