ADD REPLY • link 14 months ago waitforit • 0
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
bool isPossible(vector<int>& position, int M, int distance) {
int count = 1;
int prev = position[0];
for (int i = 1; i < position.size(); i++) {
if (position[i] - prev >= distance) {
count++;
prev = position[i];
}
}
return count >= M;
}
int solve(int N, int M, vector<int>& position) {
sort(position.begin(), position.end());
int left = 1;
int right = position[N-1] - position[0];
int result = 0;
while (left <= right) {
int mid = left + (right - left) / 2;
int main() {
int N, M;
cin >> N >> M;
vector<int> position(N);
for (int i = 0; i < N; i++) {
cin >> position[i];
}
int answer = solve(N, M, position);
cout << answer << endl;
return 0;
}
ode snippet widgetcode snippet widget