Loading Similar Posts
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
// Handle edge case: k = 0
if (k == 0) {
cout << 10000 << endl;
return 0;
}
// Sort VQ values
sort(a.begin(), a.end());
// If k > n, we can only hit n soldiers maximum
if (k > n) {
k = n;
}
// Minimum health will be 10000 - a[k-1]
int min_health = 10000 - a[k-1];
// Ensure non-negative
if (min_health < 0) {
min_health = 0;
}
cout << min_health << endl;
return 0;
}