#include <bits/stdc++.h> using namespace std; #define REP(i, n) for (int i = 0; i < (n); ++i) #define SZ(a) ((int)(a).size()) #define ALL(a) (a).begin(), (a).end() using ll = long long; using vi = vector<int>; using vvi = vector<vi>; constexpr int kInf = 1000 * 1000 * 1000 + 7; constexpr long long kInfLL = 1e18; // #include <atcoder/fenwicktree> // using namespace atcoder; // using mint = modint998244353; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n, k; cin >> n >> k; vi a(n); REP(i, n) cin >> a[i]; sort(ALL(a)); reverse(ALL(a)); int result = k - 1; while (result < n && a[result] == a[k - 1]) ++result; cout << result << '\n'; }
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 | #include <bits/stdc++.h> using namespace std; #define REP(i, n) for (int i = 0; i < (n); ++i) #define SZ(a) ((int)(a).size()) #define ALL(a) (a).begin(), (a).end() using ll = long long; using vi = vector<int>; using vvi = vector<vi>; constexpr int kInf = 1000 * 1000 * 1000 + 7; constexpr long long kInfLL = 1e18; // #include <atcoder/fenwicktree> // using namespace atcoder; // using mint = modint998244353; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n, k; cin >> n >> k; vi a(n); REP(i, n) cin >> a[i]; sort(ALL(a)); reverse(ALL(a)); int result = k - 1; while (result < n && a[result] == a[k - 1]) ++result; cout << result << '\n'; } |