#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #pragma GCC optimize("Ofast") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #define mp make_pair #define pb push_back #define ppb pop_back #define pf push_front #define ppf pop_front #define eb emplace_back #define st first #define nd second #define vt vector #define VAR(__var) #__var << ": " << __var << " " #define PAIR(__var) #__var << ": " << __var.first << ", " << __var.second << " " #define FOR(__var, __start, __end) for(int __var=__start; __var<__end; ++__var) #define FORB(__var, __start, __end) for(int __var=__start; __var>__end; --__var) #define maxi(__x, __y) __x = (__x>__y?__x:__y) #define mini(__x, __y) __x = (__x<__y?__x:__y) #define all(__var) (__var).begin(),(__var).end() #define rall(__var) (__var).rbegin(),(__var).rend() #define sz(__var) (int)(__var).size() #define satori int __test; cin>>__test; while(__test--) // flaga -DDEBUG #ifndef DEBUG #define DEBUG 0 #endif #define debug if(DEBUG) using namespace std; using namespace __gnu_pbds; template <typename T> using ord_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>; typedef int16_t i16; typedef int32_t i32; typedef int64_t i64; typedef void u0; typedef bool u1; typedef char u8; typedef uint16_t u16; typedef uint32_t u32; typedef uint64_t u64; typedef float f32; typedef double f64; typedef long double f86; const i32 INF = 1e9+2137; const i64 mod = 1420696969; // 1696969 1e9+69 1237 //templatke (patrz góra^) wzialem od wiktora przed oiem:) //gambit zadanka int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n,k; cin>>n>>k; vector<int>v(n); for(auto&x:v)cin>>x; sort(v.rbegin(),v.rend()); v.pb(-2137); for(int i=k;i<n+1;i++) { if(v[i]!=v[i-1]) { cout<<i; 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 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 | #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #pragma GCC optimize("Ofast") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #define mp make_pair #define pb push_back #define ppb pop_back #define pf push_front #define ppf pop_front #define eb emplace_back #define st first #define nd second #define vt vector #define VAR(__var) #__var << ": " << __var << " " #define PAIR(__var) #__var << ": " << __var.first << ", " << __var.second << " " #define FOR(__var, __start, __end) for(int __var=__start; __var<__end; ++__var) #define FORB(__var, __start, __end) for(int __var=__start; __var>__end; --__var) #define maxi(__x, __y) __x = (__x>__y?__x:__y) #define mini(__x, __y) __x = (__x<__y?__x:__y) #define all(__var) (__var).begin(),(__var).end() #define rall(__var) (__var).rbegin(),(__var).rend() #define sz(__var) (int)(__var).size() #define satori int __test; cin>>__test; while(__test--) // flaga -DDEBUG #ifndef DEBUG #define DEBUG 0 #endif #define debug if(DEBUG) using namespace std; using namespace __gnu_pbds; template <typename T> using ord_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>; typedef int16_t i16; typedef int32_t i32; typedef int64_t i64; typedef void u0; typedef bool u1; typedef char u8; typedef uint16_t u16; typedef uint32_t u32; typedef uint64_t u64; typedef float f32; typedef double f64; typedef long double f86; const i32 INF = 1e9+2137; const i64 mod = 1420696969; // 1696969 1e9+69 1237 //templatke (patrz góra^) wzialem od wiktora przed oiem:) //gambit zadanka int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n,k; cin>>n>>k; vector<int>v(n); for(auto&x:v)cin>>x; sort(v.rbegin(),v.rend()); v.pb(-2137); for(int i=k;i<n+1;i++) { if(v[i]!=v[i-1]) { cout<<i; return 0; } } } |