#include <iostream> #include <math.h> #include <algorithm> #include <vector> using namespace std; void printf(vector<int>arr) { for (int i = 0; i < arr.size(); i++) { cout << arr[i] << " "; }cout << endl; } bool porownaj(int a, int b) { return a > b; } int solve() { int n, k; cin >> n >> k; int ile = k; vector <int> arr(n); for (int i = 0; i < n; i++)cin >> arr[i]; sort(arr.begin(), arr.end(),porownaj); for (int i = 0; i < n; i++) if (i+1 > k) { if (arr[i] == arr[i - 1]) ile++; else break; } return ile; } int main() { cout <<solve(); return 0; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | #include <iostream> #include <math.h> #include <algorithm> #include <vector> using namespace std; void printf(vector<int>arr) { for (int i = 0; i < arr.size(); i++) { cout << arr[i] << " "; }cout << endl; } bool porownaj(int a, int b) { return a > b; } int solve() { int n, k; cin >> n >> k; int ile = k; vector <int> arr(n); for (int i = 0; i < n; i++)cin >> arr[i]; sort(arr.begin(), arr.end(),porownaj); for (int i = 0; i < n; i++) if (i+1 > k) { if (arr[i] == arr[i - 1]) ile++; else break; } return ile; } int main() { cout <<solve(); return 0; } |