Skip to content

Commit 36106fe

Browse files
Distinct Kth Max
1 parent 70f9edd commit 36106fe

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

distinct_kth_max.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)