Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <climits>
- using namespace std;
- int main() {
- int cowsAmount;
- int stallsAmount;
- vector<int> coordinates;
- //Ввод данных
- cin >> stallsAmount;
- cin >> cowsAmount;
- int k = 0;
- while (k != stallsAmount){
- int temp;
- cin >> temp;
- coordinates.push_back(temp);
- k++;
- }
- //Тело программы
- int l1 = 0;
- int r1 = stallsAmount-1;
- cowsAmount-=2;
- int minDist = INT_MAX;
- while (cowsAmount){
- int m = (coordinates[l1]+coordinates[r1])/2;
- int tempInd;
- int tempMin = coordinates[r1];
- for (int i = l1; i < r1/2+2; i++){
- if (abs(m-coordinates[i]) < tempMin){
- tempMin = abs(m-coordinates[i]);
- tempInd = i;
- }
- }
- if (abs(coordinates[l1] - coordinates[tempInd]) < abs(coordinates[tempInd] - coordinates[r1])){
- r1 = tempInd;
- } else l1 = tempInd;
- cowsAmount--;
- }
- minDist = coordinates[r1] - coordinates[l1];
- cout << minDist;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement