Skip to content

Instantly share code, notes, and snippets.

@theortsac
Created June 17, 2024 11:03
Show Gist options
  • Save theortsac/0c3149c4eb5f66ccf3f1294b8db0ce28 to your computer and use it in GitHub Desktop.
Save theortsac/0c3149c4eb5f66ccf3f1294b8db0ce28 to your computer and use it in GitHub Desktop.
#include <bits/stdc++.h>
using namespace std;
int a[505];
int main() {
int n, k;
cin >> n >> k;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
int x = 100;
while (true) { // loop infinito pois vamos quebrar dentro do próprio loop com break
int qtd = 0;
for (int i = 0; i < n; i++) {
if (a[i] >= x) qtd++;
}
if (qtd >= k) break;
x--;
}
cout << x << "\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment