Submission #831303

# Submission time Handle Problem Language Result Execution time Memory
831303 2023-08-20T04:20:38 Z manhtuan22007 Stove (JOI18_stove) C++14
0 / 100
1 ms 212 KB
#include <bits/stdc++.h>
#define int long long
#define ll long long
using namespace std;

const int maxn = 1e5 + 10;

int n , k , a[maxn];

int cal(int x){
	int j = 1 , cnt = 1;
	for(int i = 1 ; i <= n ; i ++){
		if(a[i] - a[j] + 1 <= x) continue;
		j = i;
		++cnt; 
	}
	return cnt;
}

int32_t main()
{
	cin.tie(0)->sync_with_stdio(0);
	// if(fopen(".inp" , "r")){
		// freopen(".inp" , "r" , stdin);
		// freopen(".out" , "w" , stdout);
	// }
	cin >> n >> k;
	for(int i = 1 ; i <= n ; i ++) cin >> a[i];
	int l = 0 , r = 1e9 + 1 , ans = 1e9;
	// cout << cal(3) << "\n";
	while(l <= r){
		int mid = (l + r) / 2;
		if(cal(mid) <= k) ans = mid , r = mid - 1;
		else l = mid + 1;
	}
	// cout << ans << " ";
	int res = 0 , j = 0;
	for(int i = 1 ; i <= n ; i = j + 1){
		while(a[j + 1] - a[i] + 1 <= ans && j < n){
			++j;
		}
		res += a[j] - a[i] + 1;
		// cout << i << " " << j << '\n';
	}
	
	cout << res;
}	
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -