/* * ===================================================================================== * * Author: Jakub Nowak (MrQubo) * * ===================================================================================== */ // region standard #pragma GCC optimize "-O3" #include <bits/stdc++.h> using namespace std; #pragma GCC diagnostic ignored "-Wunused-macros" namespace std { // type_traits logical operations mock for C++11 #if __cplusplus < 201700L template <bool B> using bool_constant = integral_constant<bool, B>; template <typename...> struct conjunction : true_type { }; template <typename B1> struct conjunction<B1> : B1 { }; template <typename B1, typename... Bn> struct conjunction<B1, Bn...> : conditional<bool(B1::value), conjunction<Bn...>, B1>::type { }; template <class...> struct disjunction : false_type { }; template <class B1> struct disjunction<B1> : B1 { }; template <class B1, class... Bn> struct disjunction<B1, Bn...> : conditional<bool(B1::value), B1, disjunction<Bn...>>::type { }; template <typename B> struct negation : bool_constant<!bool(B::value)> { }; #endif } #define guard(x) if (!(x)) #define _CAT(A, B) A ## B #define CAT(A, B) _CAT(A, B) #define _CAT3(A, B, C) A ## B ## C #define CAT3(A, B, C) _CAT3(A, B, C) #define _STR(...) #__VA_ARGS__ #define STR(...) _STR(__VA_ARGS__) #define _FIRST(F, ...) F #define FIRST(...) _FIRST(__VA_ARGS__, ) #define SKIP1(F, ...) __VA_ARGS__ #define SKIP2(F, ...) SKIP1(__VA_ARGS__, ) #define SKIP3(F, ...) SKIP2(__VA_ARGS__, ) #define SKIP4(F, ...) SKIP3(__VA_ARGS__, ) #define SKIP5(F, ...) SKIP4(__VA_ARGS__, ) #define SKIP6(F, ...) SKIP5(__VA_ARGS__, ) #define SKIP7(F, ...) SKIP6(__VA_ARGS__, ) #define SKIP8(F, ...) SKIP7(__VA_ARGS__, ) #define SKIP9(F, ...) SKIP8(__VA_ARGS__, ) #define SKIP10(F, ...) SKIP9(__VA_ARGS__, ) #define SKIP11(F, ...) SKIP10(__VA_ARGS__, ) #define SKIP12(F, ...) SKIP11(__VA_ARGS__, ) #define SKIP(N, ...) CAT(SKIP, N)(__VA_ARGS__, ) #define COUNT(...) FIRST(SKIP12(__VA_ARGS__, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1)) #ifdef DEBUG #define MAGIC do { clog << boolalpha; } while(0) #define PRINT(msg) do { clog << "DBG:" << __LINE__ << "> " << msg << endl; } while(0) #else #define MAGIC do { ios_base::sync_with_stdio(false); cin.tie(nullptr); } while(0) #define PRINT(msg) do { } while(0) #define clog DONT_USE_CLOG!!!!!!! #define cerr DONT_USE_CERR!!!!!!! #define endl DONT_USE_ENDL!!!!!!! #endif // DEBUG #define _DBG1(x, ...) STR(x) << ": " << flush << (x) #define _DBG2(x, ...) STR(x) << ": " << flush << (x) << " \t" << _DBG1(__VA_ARGS__) #define _DBG3(x, ...) STR(x) << ": " << flush << (x) << " \t" << _DBG2(__VA_ARGS__) #define _DBG4(x, ...) STR(x) << ": " << flush << (x) << " \t" << _DBG3(__VA_ARGS__) #define _DBG5(x, ...) STR(x) << ": " << flush << (x) << " \t" << _DBG4(__VA_ARGS__) #define _DBG6(x, ...) STR(x) << ": " << flush << (x) << " \t" << _DBG5(__VA_ARGS__) #define _DBG7(x, ...) STR(x) << ": " << flush << (x) << " \t" << _DBG6(__VA_ARGS__) #define _DBG8(x, ...) STR(x) << ": " << flush << (x) << " \t" << _DBG7(__VA_ARGS__) #define _DBG9(x, ...) STR(x) << ": " << flush << (x) << " \t" << _DBG8(__VA_ARGS__) #define _DBG10(x, ...) STR(x) << ": " << flush << (x) << " \t" << _DBG9(__VA_ARGS__) #define _DBG11(x, ...) STR(x) << ": " << flush << (x) << " \t" << _DBG10(__VA_ARGS__) #define _DBG12(x, ...) STR(x) << ": " << flush << (x) << " \t" << _DBG11(__VA_ARGS__) #define _DBG(...) CAT(_DBG, COUNT(__VA_ARGS__))(__VA_ARGS__, ) #define DBG(...) PRINT(_DBG(__VA_ARGS__)) #define PDBG(msg, ...) PRINT(msg << _DBG(__VA_ARGS__)) #define ST first #define ND second #define EM emplace #define EB emplace_back #define IN insert #define PB push_back #define vec vector #define uset unordered_set #define umap unordered_map using ll = long long; using ull = unsigned long long; using ld = long double; using str = string; using PI = pair<int, int>; using PLL = pair<ll, ll>; using VI = vec<int>; using VVI = vec<VI>; using VLL = vec<ll>; #define ALL(x) begin((x)), end((x)) template <typename T> inline T posmod(T x, T m) { return (x % m + m) % m; } template <typename T> inline T mini(T & a, T const & b) { return a = min(a, b); } template <typename T> inline T maxi(T & a, T const & b) { return a = max(a, b); } template <typename T> inline T fpow(T a, ull b, T M) { T r(1); while (b > 0) { if (b & 1) { r *= a; r %= M; } a *= a; a %= M; b >>= 1; } return r; } // ostream out ostream template <typename Iter> void ooo(Iter first, Iter last, char const * delim, ostream & os) { while (first != last) { os << *(first++) << delim; } } // ostream out template <typename Iter> inline void oo(Iter first, Iter last, char const * delim) { ooo(first, last, delim, cout); } // container ostream out template <typename C> inline void coo(C V, char const * delim) { ooo(ALL(V), delim, cout); } // infix out ostream template <typename Iter> void ioo(Iter first, Iter last, char const * delim, ostream & os) { if (first == last) return; os << *(first++); while (first != last) { os << delim << *(first++); } } // infix out template <typename Iter> inline void io(Iter first, Iter last, char const * delim) { ioo(first, last, delim, cout); } // container infix out template <typename C> inline void cio(C V, char const * delim) { ioo(ALL(V), delim, cout); } #ifdef DEBUG template <typename T, typename S> ostream & operator << (ostream & os, pair<T, S> const & p) { return os << "(" << p.ST << ", " << p.ND << ")" << flush; } template <typename... Args> ostream & operator << (ostream & os, map<Args...> const & S) { os << "{"; ioo(ALL(S), ", ", os); return os << "}" << flush; } template <typename... Args> ostream & operator << (ostream & os, umap<Args...> const & S) { os << "{"; ioo(ALL(S), ", ", os); return os << "}" << flush; } template <typename... Args> ostream & operator << (ostream & os, multimap<Args...> const & S) { os << "{"; ioo(ALL(S), ", ", os); return os << "}" << flush; } template <typename... Args> ostream & operator << (ostream & os, unordered_multimap<Args...> const & S) { os << "{"; ioo(ALL(S), ", ", os); return os << "}" << flush; } template <typename... Args> ostream & operator << (ostream & os, set<Args...> const & S) { os << "{"; ioo(ALL(S), ", ", os); return os << "}" << flush; } template <typename... Args> ostream & operator << (ostream & os, uset<Args...> const & S) { os << "{"; ioo(ALL(S), ", ", os); return os << "}" << flush; } template <typename... Args> ostream & operator << (ostream & os, multiset<Args...> const & S) { os << "{"; ioo(ALL(S), ", ", os); return os << "}" << flush; } template <typename... Args> ostream & operator << (ostream & os, unordered_multiset<Args...> const & S) { os << "{"; ioo(ALL(S), ", ", os); return os << "}" << flush; } template <typename... Args> ostream & operator << (ostream & os, vector<Args...> const & V) { os << "["; ioo(ALL(V), ", ", os); return os << "]" << flush; } template <typename... Args> ostream & operator << (ostream & os, valarray<Args...> const & VA) { os << "["; ioo(ALL(VA), ", ", os); return os << "]" << flush; } #endif // DEBUG // istream in istream template <typename Iter> void iii(Iter to, ll n, istream & is) { while(n--) { is >> *(to++); } } // istream in template <typename Iter> void ii(Iter to, ll const & n) { iii(to, n, cin); } // container istream in template <typename C> void cii(C & V, ll const & n) { iii(begin(V), n, cin); } // container istream in template <typename C> C cii(ll const & n) { C V(n); iii(begin(V), n, cin); return V; } // endregion struct Solve { int N, K; VI A; void solve() { cin >> N >> K; A = cii<VI>(N); sort(ALL(A), greater()); int k = K-1; for (; k < N-1; k += 1) { if (A[k] != A[k+1]) break; } cout << (k+1) << '\n'; } }; Solve sol; void solve() { sol.solve(); } int main() { MAGIC; solve(); }
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 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 | /* * ===================================================================================== * * Author: Jakub Nowak (MrQubo) * * ===================================================================================== */ // region standard #pragma GCC optimize "-O3" #include <bits/stdc++.h> using namespace std; #pragma GCC diagnostic ignored "-Wunused-macros" namespace std { // type_traits logical operations mock for C++11 #if __cplusplus < 201700L template <bool B> using bool_constant = integral_constant<bool, B>; template <typename...> struct conjunction : true_type { }; template <typename B1> struct conjunction<B1> : B1 { }; template <typename B1, typename... Bn> struct conjunction<B1, Bn...> : conditional<bool(B1::value), conjunction<Bn...>, B1>::type { }; template <class...> struct disjunction : false_type { }; template <class B1> struct disjunction<B1> : B1 { }; template <class B1, class... Bn> struct disjunction<B1, Bn...> : conditional<bool(B1::value), B1, disjunction<Bn...>>::type { }; template <typename B> struct negation : bool_constant<!bool(B::value)> { }; #endif } #define guard(x) if (!(x)) #define _CAT(A, B) A ## B #define CAT(A, B) _CAT(A, B) #define _CAT3(A, B, C) A ## B ## C #define CAT3(A, B, C) _CAT3(A, B, C) #define _STR(...) #__VA_ARGS__ #define STR(...) _STR(__VA_ARGS__) #define _FIRST(F, ...) F #define FIRST(...) _FIRST(__VA_ARGS__, ) #define SKIP1(F, ...) __VA_ARGS__ #define SKIP2(F, ...) SKIP1(__VA_ARGS__, ) #define SKIP3(F, ...) SKIP2(__VA_ARGS__, ) #define SKIP4(F, ...) SKIP3(__VA_ARGS__, ) #define SKIP5(F, ...) SKIP4(__VA_ARGS__, ) #define SKIP6(F, ...) SKIP5(__VA_ARGS__, ) #define SKIP7(F, ...) SKIP6(__VA_ARGS__, ) #define SKIP8(F, ...) SKIP7(__VA_ARGS__, ) #define SKIP9(F, ...) SKIP8(__VA_ARGS__, ) #define SKIP10(F, ...) SKIP9(__VA_ARGS__, ) #define SKIP11(F, ...) SKIP10(__VA_ARGS__, ) #define SKIP12(F, ...) SKIP11(__VA_ARGS__, ) #define SKIP(N, ...) CAT(SKIP, N)(__VA_ARGS__, ) #define COUNT(...) FIRST(SKIP12(__VA_ARGS__, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1)) #ifdef DEBUG #define MAGIC do { clog << boolalpha; } while(0) #define PRINT(msg) do { clog << "DBG:" << __LINE__ << "> " << msg << endl; } while(0) #else #define MAGIC do { ios_base::sync_with_stdio(false); cin.tie(nullptr); } while(0) #define PRINT(msg) do { } while(0) #define clog DONT_USE_CLOG!!!!!!! #define cerr DONT_USE_CERR!!!!!!! #define endl DONT_USE_ENDL!!!!!!! #endif // DEBUG #define _DBG1(x, ...) STR(x) << ": " << flush << (x) #define _DBG2(x, ...) STR(x) << ": " << flush << (x) << " \t" << _DBG1(__VA_ARGS__) #define _DBG3(x, ...) STR(x) << ": " << flush << (x) << " \t" << _DBG2(__VA_ARGS__) #define _DBG4(x, ...) STR(x) << ": " << flush << (x) << " \t" << _DBG3(__VA_ARGS__) #define _DBG5(x, ...) STR(x) << ": " << flush << (x) << " \t" << _DBG4(__VA_ARGS__) #define _DBG6(x, ...) STR(x) << ": " << flush << (x) << " \t" << _DBG5(__VA_ARGS__) #define _DBG7(x, ...) STR(x) << ": " << flush << (x) << " \t" << _DBG6(__VA_ARGS__) #define _DBG8(x, ...) STR(x) << ": " << flush << (x) << " \t" << _DBG7(__VA_ARGS__) #define _DBG9(x, ...) STR(x) << ": " << flush << (x) << " \t" << _DBG8(__VA_ARGS__) #define _DBG10(x, ...) STR(x) << ": " << flush << (x) << " \t" << _DBG9(__VA_ARGS__) #define _DBG11(x, ...) STR(x) << ": " << flush << (x) << " \t" << _DBG10(__VA_ARGS__) #define _DBG12(x, ...) STR(x) << ": " << flush << (x) << " \t" << _DBG11(__VA_ARGS__) #define _DBG(...) CAT(_DBG, COUNT(__VA_ARGS__))(__VA_ARGS__, ) #define DBG(...) PRINT(_DBG(__VA_ARGS__)) #define PDBG(msg, ...) PRINT(msg << _DBG(__VA_ARGS__)) #define ST first #define ND second #define EM emplace #define EB emplace_back #define IN insert #define PB push_back #define vec vector #define uset unordered_set #define umap unordered_map using ll = long long; using ull = unsigned long long; using ld = long double; using str = string; using PI = pair<int, int>; using PLL = pair<ll, ll>; using VI = vec<int>; using VVI = vec<VI>; using VLL = vec<ll>; #define ALL(x) begin((x)), end((x)) template <typename T> inline T posmod(T x, T m) { return (x % m + m) % m; } template <typename T> inline T mini(T & a, T const & b) { return a = min(a, b); } template <typename T> inline T maxi(T & a, T const & b) { return a = max(a, b); } template <typename T> inline T fpow(T a, ull b, T M) { T r(1); while (b > 0) { if (b & 1) { r *= a; r %= M; } a *= a; a %= M; b >>= 1; } return r; } // ostream out ostream template <typename Iter> void ooo(Iter first, Iter last, char const * delim, ostream & os) { while (first != last) { os << *(first++) << delim; } } // ostream out template <typename Iter> inline void oo(Iter first, Iter last, char const * delim) { ooo(first, last, delim, cout); } // container ostream out template <typename C> inline void coo(C V, char const * delim) { ooo(ALL(V), delim, cout); } // infix out ostream template <typename Iter> void ioo(Iter first, Iter last, char const * delim, ostream & os) { if (first == last) return; os << *(first++); while (first != last) { os << delim << *(first++); } } // infix out template <typename Iter> inline void io(Iter first, Iter last, char const * delim) { ioo(first, last, delim, cout); } // container infix out template <typename C> inline void cio(C V, char const * delim) { ioo(ALL(V), delim, cout); } #ifdef DEBUG template <typename T, typename S> ostream & operator << (ostream & os, pair<T, S> const & p) { return os << "(" << p.ST << ", " << p.ND << ")" << flush; } template <typename... Args> ostream & operator << (ostream & os, map<Args...> const & S) { os << "{"; ioo(ALL(S), ", ", os); return os << "}" << flush; } template <typename... Args> ostream & operator << (ostream & os, umap<Args...> const & S) { os << "{"; ioo(ALL(S), ", ", os); return os << "}" << flush; } template <typename... Args> ostream & operator << (ostream & os, multimap<Args...> const & S) { os << "{"; ioo(ALL(S), ", ", os); return os << "}" << flush; } template <typename... Args> ostream & operator << (ostream & os, unordered_multimap<Args...> const & S) { os << "{"; ioo(ALL(S), ", ", os); return os << "}" << flush; } template <typename... Args> ostream & operator << (ostream & os, set<Args...> const & S) { os << "{"; ioo(ALL(S), ", ", os); return os << "}" << flush; } template <typename... Args> ostream & operator << (ostream & os, uset<Args...> const & S) { os << "{"; ioo(ALL(S), ", ", os); return os << "}" << flush; } template <typename... Args> ostream & operator << (ostream & os, multiset<Args...> const & S) { os << "{"; ioo(ALL(S), ", ", os); return os << "}" << flush; } template <typename... Args> ostream & operator << (ostream & os, unordered_multiset<Args...> const & S) { os << "{"; ioo(ALL(S), ", ", os); return os << "}" << flush; } template <typename... Args> ostream & operator << (ostream & os, vector<Args...> const & V) { os << "["; ioo(ALL(V), ", ", os); return os << "]" << flush; } template <typename... Args> ostream & operator << (ostream & os, valarray<Args...> const & VA) { os << "["; ioo(ALL(VA), ", ", os); return os << "]" << flush; } #endif // DEBUG // istream in istream template <typename Iter> void iii(Iter to, ll n, istream & is) { while(n--) { is >> *(to++); } } // istream in template <typename Iter> void ii(Iter to, ll const & n) { iii(to, n, cin); } // container istream in template <typename C> void cii(C & V, ll const & n) { iii(begin(V), n, cin); } // container istream in template <typename C> C cii(ll const & n) { C V(n); iii(begin(V), n, cin); return V; } // endregion struct Solve { int N, K; VI A; void solve() { cin >> N >> K; A = cii<VI>(N); sort(ALL(A), greater()); int k = K-1; for (; k < N-1; k += 1) { if (A[k] != A[k+1]) break; } cout << (k+1) << '\n'; } }; Solve sol; void solve() { sol.solve(); } int main() { MAGIC; solve(); } |