We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 70f9edd commit 36106feCopy full SHA for 36106fe
distinct_kth_max.cpp
@@ -0,0 +1,32 @@
1
+# include<bits/stdc++.h>
2
+# define f(i,a,b) for(int i = a; i < b; i++)
3
+using namespace std;
4
+
5
+int main()
6
+{
7
8
+ // Online Judge Macro
9
+ #ifndef ONLINE_JUDGE
10
+ freopen("input.txt", "r", stdin);
11
+ freopen("output.txt", "w", stdout);
12
+ #endif
13
14
+ // Variables and I/O
15
+ int n, k;
16
+ cin>>n;
17
+ vector<int> x(n);
18
+ for(int& i : x){ cin>>i; }
19
+ cin>>k;
20
21
+ // Finding Difference Set
22
+ set<int> temp(x.begin(), x.end());
23
+ f(i, 0, n){
24
+ f(j, i + 1, n){
25
+ temp.insert(abs(x[j] - x[i]));
26
+ }
27
28
29
+ // Answer
30
+ cout<<*std::next(temp.begin(), temp.size() - k);
31
+ return 0;
32
+}
0 commit comments