bai 3 - hsg9 vinhphuc 2021

20/04/2023

nghi van khong AC full test

Code
#include <bits/stdc++.h>
using namespace std;

int main(){
	int n,k;
	cin >> n >> k;
	int a[n+1];
	a[0] = 1;
	for (int i=1;i<= n;i++) cin >> a[i];
	int dp[n+1];
	for (int i=2;i<= n;i++) dp[i] = a[i] - a[i-1];
	sort(dp+2, dp + n + 1);
	int i=n;
	while (k--) {
		dp[i] = dp[i]/2;
		if (dp[i] < dp[i-1]) sort(dp+2, dp + n + 1);
	}
	cout << dp[n];
	return 0;
}