solution
stringlengths
11
983k
difficulty
int64
0
21
language
stringclasses
2 values
def test(a, k, pos): r = list(reversed(sorted(a.copy()))) countLast = r[k-1] s = 0 for i in range(k, len(r)): if r[i] == countLast: s += 1 ans = [] a = list(reversed(a)) for i in range(len(a)): if a[i] > countLast or (a[i] == countLast and s == 0): ans.append(a[i]) elif a[i] == countLast: s -= 1 print(list(reversed(ans))[pos-1]) n = int(input()) a = list(map(int ,input().split())) m = int(input()) for i in range(m): k, pos = map(int, input().split()) test(a, k, pos)
10
PYTHON3
#include <bits/stdc++.h> using namespace std; hash<string> hfn; const int inf = 2e9; const long long mod = 1e9 + 7; const long double eps = 1e-8; const long long biginf = 2e18; bool comp(pair<int, int> a, pair<int, int> b) { if (a.first == b.first) return a.second > b.second; return a.first < b.first; } void solve() { int n; cin >> n; vector<pair<int, int> > v(n); vector<int> stv(n); for (int i = 0; i < n; i++) { cin >> v[i].first; v[i].second = i; stv[i] = v[i].first; } sort((v).begin(), (v).end(), comp); int q; cin >> q; for (int i = 0; i < q; i++) { int k, ind; cin >> k >> ind; ind--; int pos = n - k + ind; vector<pair<int, int> > r; for (int i = n - k; i < n; i++) r.push_back(make_pair(v[i].second, v[i].first)); sort((r).begin(), (r).end()); cout << r[ind].second << endl; } } void multisolve() { int t; cin >> t; while (t--) solve(); } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); solve(); }
10
CPP
from math import * from copy import copy def maximum(list_ticket): for i in range(len(list_ticket)): if i == 0: ma=list_ticket[i] else: ma=max(ma,list_ticket[i]) ma = list_ticket.index(ma) list_ticket.insert(ma,0) list_ticket.pop(ma+1) return ma n = int(input()) a = list(map(int, input().split())) m = int(input()) for i in range(m): b = copy(a) q = [] array = list(map(int, input().split())) for i in range(array[0]): q.append(maximum(b)) q.sort() q1 = [] for i in range(len(q)): q1.append(a[q[i]]) q1 = list(map(str, q1)) print(q1[array[1]-1])
10
PYTHON3
#include <bits/stdc++.h> using namespace std; bool cmp(pair<int, int> p1, pair<int, int> p2) { if (p1.first == p2.first) { return p1.second < p2.second; } else { return p1.first > p2.first; } } int fc(int k, int pos, vector<pair<int, int> > a, vector<int> b) { vector<int> y; for (int i = 0; i < k; i++) { y.push_back(a[i].second); } sort(y.begin(), y.end()); return y[pos - 1]; } int main() { int n; cin >> n; vector<pair<int, int> > a(n); vector<int> b(n); for (int i = 0; i < n; i++) { cin >> a[i].first; a[i].second = i; b[i] = a[i].first; } sort(a.begin(), a.end(), cmp); int q; cin >> q; for (int i = 0; i < q; i++) { int k, pos; cin >> k >> pos; int x = fc(k, pos, a, b); cout << b[x] << endl; } return 0; }
10
CPP
#include <bits/stdc++.h> using namespace std; void solve() { long long n; cin >> n; vector<long long> v(n), so(n); for (long long i = 0; i < n; ++i) { cin >> v[i]; so[i] = v[i]; } sort(so.begin(), so.end()); long long m; cin >> m; for (long long i = 0; i < m; ++i) { long long k, pos; cin >> k >> pos; map<long long, long long> mp; for (long long j = n - k; j < n; ++j) { mp[so[j]]++; } for (long long j = 0; j < n; ++j) { if (mp.count(v[j]) and mp[v[j]] > 0) { --pos; mp[v[j]]--; } if (pos == 0) { cout << v[j] << endl; break; } } } } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); { solve(); } return 0; }
10
CPP
a = int(input()) b = list(map(int, input().split())) for i in range(a): b[i] = (b[i], -i) b.sort() k = int(input()) for q in range(k): a = list(map(int, input().split())) l = a[0] p = a[1] print(sorted(b[-l:], key = lambda x: -x[1])[p - 1][0])
10
PYTHON3
#include <bits/stdc++.h> using namespace std; const long long INF = 1e9 + 123, MAXN = 2e5 + 47; long long p = 41; template <class T> istream& operator>>(istream& in, vector<T>& a) { for (auto& i : a) in >> i; return in; } template <class T> ostream& operator<<(ostream& out, vector<T>& a) { for (auto& i : a) out << i << " "; return out; } template <class T, class U> istream& operator>>(istream& in, vector<pair<T, U>>& a) { for (auto& i : a) in >> i.first >> i.second; return in; } template <class T, class U> ostream& operator<<(ostream& out, vector<pair<T, U>>& a) { for (auto& i : a) out << i.first << " " << i.second << endl; return out; } bool cmp(pair<long long, long long>& a, pair<long long, long long>& b) { if (a.first > b.first) return 1; if (a.first < b.first) return 0; if (a.first == b.first) { if (a.second < b.second) return 1; else return 0; } } signed main() { setlocale(LC_ALL, "rus"); ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long n; cin >> n; vector<long long> a(n); cin >> a; vector<pair<long long, long long>> p(n); for (long long i = 0; i < n; ++i) p[i] = make_pair(a[i], i); sort(p.begin(), p.end(), cmp); long long m; cin >> m; while (m--) { long long k, pos; cin >> k >> pos; vector<long long> b(n, 0); for (long long i = 0; i < k; ++i) b[p[i].second] = p[i].first; vector<long long> ans; for (long long i = 0; i < n; ++i) if (b[i]) ans.push_back(b[i]); cout << ans[pos - 1] << endl; } }
10
CPP
#include <bits/stdc++.h> using namespace std; const int INF = 1e9 + 1; const int N = 1e6 * 3; const double EPS = 1 / 1e10; vector<int> v, v1; set<pair<long long, long long> > second; bool cmp(pair<long long, long long> a, pair<long long, long long> b) { return (a.first > b.first) || (a.first == b.first && a.second < b.second); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int q, n; cin >> n; pair<long long, long long> a[n]; for (int i = 0; i < n; ++i) { cin >> a[i].first; a[i].second = i; } sort(a, a + n, cmp); cin >> q; for (int w = 1; w <= q; w++) { int k, pos; second.clear(); cin >> k >> pos; for (int i = 0; i < k; i++) second.insert(make_pair(a[i].second, a[i].first)); set<pair<long long, long long> >::iterator it = second.begin(); for (int i = 0; i < pos - 1; it++, i++) ; cout << it->second << "\n"; } return 0; }
10
CPP
#include <bits/stdc++.h> using namespace std; const long double pi = acos(-1); const long long md = 1e9 + 7; long long n, q, a, i, k, pos; vector<pair<long long, long long> > v, ans; bool comp(pair<long long, long long> a, pair<long long, long long> b) { if (a.first == b.first) return a.second < b.second; else return a > b; } int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> n; for (i = 1; i <= n; i++) { cin >> a; v.push_back({a, i}); } sort(v.begin(), v.end(), comp); cin >> q; while (q--) { cin >> k >> pos; ans.clear(); for (i = 0; i < k; i++) { ans.push_back({v[i].second, v[i].first}); } sort(ans.begin(), ans.end()); pos--; cout << ans[pos].second << '\n'; } return 0; }
10
CPP
n = int(input()) a = [int(x) for x in input().split()] m = int(input()) for i in range(m): kj, posj = map(int, input().split()) a_copy = [x for x in a] for u in range(n - kj): mid = 0 for uuu in range(len(a_copy)): if a_copy[uuu] <= a_copy[mid]: mid = uuu a_copy.pop(mid) print(a_copy[posj-1])
10
PYTHON3
#include <bits/stdc++.h> using namespace std; bool comp(pair<int, int> a, pair<int, int> b) { if (a.first == b.first) return a.second > b.second; return a.first < b.first; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, m; cin >> n; vector<int> a_f(n); vector<pair<int, int>> a(n); for (int i = 0; i < n; i++) cin >> a[i].first, a[i].second = i, a_f[i] = a[i].first; sort(a.begin(), a.end(), comp); cin >> m; vector<vector<int>> tmp(n); vector<bool> used(n); for (int i = 1; i <= n; i++) { for (int j = 0; j < n - i; j++) used[a[j].second] = true; for (int j = 0; j < n; j++) { if (used[j]) continue; tmp[i - 1].push_back(a_f[j]); } used.assign(n, false); } while (m--) { int j, pos; cin >> j >> pos; cout << tmp[j - 1][pos - 1] << '\n'; } return 0; }
10
CPP
n = int(input()) arr = list(map(int, input().split())) m = int(input()) q = [] for i in range(m): a, b = map(int, input().split()) q.append((a, b)) def f(arr, m): vis = [False] * len(arr) arr2 = [] for i in range(len(arr)): arr2.append([arr[i], n - i]) arr2.sort(reverse=True) arr2 = arr2[:m] for i in range(len(arr2)): arr2[i][1] = n - arr2[i][1] arr2.sort(key=lambda x: x[1]) res = [] for i in range(len(arr2)): res.append(arr2[i][0]) return res for i in q: x = f(arr, i[0]) print(x[i[1] - 1])
10
PYTHON3
#include <bits/stdc++.h> using namespace std; const long long int mod = 1e9 + 7; const long double error = 2e-6; const long double PI = acosl(-1); inline long long int MOD(long long int x, long long int m = mod) { long long int y = x % m; return (y >= 0) ? y : y + m; } const int inf = 1e9; const long long int infl = 1061109567; const int nmax = 1000 + 10; bool cmp(pair<int, int> p1, pair<int, int> p2) { if (p1.first != p2.first) return p1.first < p2.first; return p1.second > p2.second; } int main() { int n; cin >> n; int i; vector<pair<int, int> > vc(n); vector<int> ara; for (i = 0; i < n; i++) { int xx; cin >> xx; ara.push_back(xx); vc[i] = {xx, i}; } sort(vc.begin(), vc.end(), cmp); int m; cin >> m; for (i = 1; i <= m; i++) { int k, pos; cin >> k >> pos; vector<int> sv; int j; for (j = n - 1; j >= n - k; j--) { sv.push_back(vc[j].second); } sort(sv.begin(), sv.end()); cout << ara[sv[pos - 1]] << "" << endl; } return 0; }
10
CPP
import sys input = sys.stdin.buffer.readline mx = 2*10**5 + 1 bit = [0]*(mx) def add(idx): idx += 1 while idx < mx: bit[idx] += 1 idx += idx & - idx # log(n) !!! def lower_bound(val): pos = 0 tot = 0 for i in range(20,-1,-1): if pos + (1 << i) < mx and tot + bit[pos + (1 << i)] < val: tot += bit[pos + (1 << i)] pos += (1 << i) return pos n = int(input()) a = list(map(int,input().split())) new_el = sorted(list(range(n)), key = lambda i: (-a[i], i)) m = int(input()) queries = [] answers = [0]*m for i in range(m): k,p = map(int,input().split()) queries.append([k,p,i]) queries.sort() curr_len = 0 for i in range(m): k,pos,query_idx = queries[i] while curr_len < k: add(new_el[curr_len]) curr_len += 1 answers[query_idx] = a[lower_bound(pos)] print(*answers)
10
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> arr(n); for (int i = 0; i < n; i++) { cin >> arr[i]; } int m; cin >> m; while (m--) { map<int, pair<int, vector<int>>> mp; int k, pos; cin >> k >> pos; vector<int> temp; mp[0] = make_pair(0, temp); for (int i = 0; i < n; i++) { vector<pair<int, vector<int>>> toadd; for (auto& a : mp) { if (a.first >= k) continue; int nsm = a.second.first + arr[i]; vector<int> temp = a.second.second; ; temp.push_back(arr[i]); toadd.push_back(make_pair(nsm, temp)); } for (auto& a : toadd) { if (!mp.count(a.second.size()) || mp[a.second.size()].first < a.first || (mp[a.second.size()].first == a.first && mp[a.second.size()].second > a.second)) { mp[a.second.size()] = a; } } } auto e = mp.end(); e--; cout << e->second.second[pos - 1] << "\n"; } return 0; }
10
CPP
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 10, mod = 1e9 + 7; int a[N]; vector<pair<int, int> > vec; bool cmp(pair<int, int> a, pair<int, int> b) { if (a.first != b.first) return a.first > b.first; else return a.second < b.second; } void solve() { int k, pos; cin >> k >> pos; vector<int> ans; for (int i = 0; i < k; i++) { ans.push_back(vec[i].second); } sort(ans.begin(), ans.end()); cout << a[ans[pos - 1]] << endl; } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; vec.push_back({a[i], i}); } int m; cin >> m; sort(vec.begin(), vec.end(), cmp); while (m--) solve(); }
10
CPP
import sys def main(): n = int(input()) al = [[int(x),n-i] for i,x in enumerate(input().split())] al.sort() al.reverse() arr = [[[]for i in range(n)]for i in range(n)] for i in range(1,n+1): for j in range(i-1,n): arr[j][n-al[i-1][1]] = al[i-1][0] for i in range(n): arr[i] = list(filter(None, arr[i])) q = int(input()) for _ in range(q): k,ind = map(int,input().split()) print(arr[k-1][ind-1]) main()
10
PYTHON3
n = int(input()) b = list(map(int,input().split())) a = [[0] * 2 for i in range(n)] for i in range(n): a[i][0] = b[i] a[i][1] = i for i in range(n-1): for j in range(n-i-1): if a[j][0] > a[j+1][0]: a[j], a[j+1] = a[j+1], a[j] elif (a[j][0] == a[j + 1][0]) and (a[j][1] < a[j + 1][1]): a[j], a[j+1] = a[j+1], a[j] m = int(input()) for k in range(m): k, ind = map(int,input().split()) ans = [[0] * 2 for i in range(k)] for i in range(k): ans[i][0] = a[n - i - 1][1] ans[i][1] = a[n - i - 1][0] ans.sort() print(ans[ind - 1][1])
10
PYTHON3
n = int(input()) a = list(map(int, input().split())) m = int(input()) for i in range(m): k, pos = map(int, input().split()) save = [] for j in range(len(a)): save.append(a[j]) ans = [] for x in range(k): maximum = 0 pr = -1 for j in range(len(save)): if save[j] > maximum: maximum = save[j] pr = j ans.append(maximum) save.pop(pr) ans.sort() answer = [] for i in range(len(a)): if a[i] in ans: answer.append(a[i]) ans.pop(ans.index(a[i])) print(answer[pos - 1])
10
PYTHON3
n=int(input()) s=sorted([[v,-i] for i,v in enumerate(map(int,input().split()))]) for _ in range(int(input())): k,i=map(int,input().split()) ans=sorted(s[-k:],key=lambda x:-x[1]) print(ans[i-1][0])
10
PYTHON3
#include <bits/stdc++.h> using namespace std; long long N = 200000; vector<bool> visited(N + 1, false); bool isprime(long long x) { for (long long i = 2; i <= sqrt(x); i++) { if (x % i == 0) return false; } return true; } void findfact(long long x, map<long long, vector<long long>>& m) { for (long long i = 3; i * i <= x; i += 2) { if (x % i == 0) { if (i == x / i) m[x].push_back(i); else { m[x].push_back(i); m[x].push_back(x / i); } break; } } return; } struct cmp { bool operator()(const pair<int, int>& a, const pair<int, int>& b) { if (a.first > b.first) return false; else if (a.first < b.first) return true; if (a.second < b.second) return false; return true; } }; bool isPalindrome(string t) { long long st = 0; long long end = t.size() - 1; while (st <= end) { if (t[st] != t[end]) return false; st++; end--; } return true; } long long gcd(long long a, long long b) { if (b == 0) return a; return gcd(b, a % b); } bool pow2(long long x) { return x && (!(x & (x - 1))); } unsigned long long factorial(unsigned long long n) { return (n == 1 || n == 0) ? 1 : n * factorial(n - 1); } unsigned long long binomialCoeff(unsigned long long n, unsigned long long k) { unsigned long long res = 1; if (k > n - k) k = n - k; for (unsigned long long i = 0; i < k; ++i) { res *= (n - i); res /= (i + 1); } return res; } vector<long long> hp; void primeFactors(long long n) { while (n % 2 == 0) { hp.push_back(2); n = n / 2; } for (int i = 3; i <= sqrt(n); i = i + 2) { while (n % i == 0) { hp.push_back(i); n = n / i; } } if (n > 2) hp.push_back(n); } long long minFlipsMonoIncr(string S) { int flip = 0; int ones = 0; bool flag = false; for (int i = 0; i < S.size(); i++) { if (S[i] - '0' == 1) flag = true; if (flag && S[i] - '0' == 0) flip++; else if (S[i] == '1') ones++; if (flip > ones) flip = ones; } return flip; } void dfs() {} int main() { ios_base::sync_with_stdio(0); long long n; cin >> n; vector<long long> arr(n + 1); for (long long i = 1; i <= n; i++) cin >> arr[i]; long long m; cin >> m; while (m--) { long long k, pos; cin >> k >> pos; priority_queue<pair<long long, long long>, vector<pair<long long, long long>>, cmp> pq; for (long long i = 1; i <= n; i++) pq.push(make_pair(arr[i], i)); vector<long long> temp(n + 1, -1); while (k--) { temp[pq.top().second] = pq.top().first; pq.pop(); } long long ele = 0; long long i; for (i = 1; i <= n; i++) { if (temp[i] == -1) continue; else ele++; if (ele == pos) break; } cout << temp[i] << "\n"; } }
10
CPP
#include <bits/stdc++.h> using namespace std; using LL = long long; const LL INF = INT_MAX; const int N = 1e5 + 7; const LL MOD = 1e9 + 7; void ArrayIn(int size, int a[]) { for (int i = 0; i < size; i++) scanf("%d", &a[i]); } void ArrayOut(int size, int a[]) { for (int i = 0; i < size; i++) printf("%d ", a[i]); printf("\n"); } int main() { int n, m, i; scanf("%d", &n); vector<pair<int, int>> ar(n + 1); for (i = 1; i <= n; i++) { int item; scanf("%d", &item); ar[i] = make_pair(item, i); } sort(ar.rbegin(), ar.rend() - 1); for (i = 1; i <= n; i++) { int j = i; while (ar[j].first == ar[j + 1].first && j < n) j++; reverse(ar.begin() + i, ar.begin() + j + 1); i = j; } scanf("%d", &m); while (m--) { vector<pair<int, int>> cur = ar; int k, pos; scanf("%d%d", &k, &pos); for (i = 1; i <= k; i++) { swap(cur[i].first, cur[i].second); } sort(cur.begin() + 1, cur.begin() + 1 + k); printf("%d\n", cur[pos].second); } return 0; }
10
CPP
#include <bits/stdc++.h> using namespace std; const long long int no = 3e6 + 5, modulo = 1e9 + 7, inf = 1e18, N = 3e3 + 1; long long int ar[no], br[no], cr[no]; void solve() { long long int n = 0, m = 0, a = 0, b = 0, c = 0, d = 0, x = 0, y = 0, z = 0, w = 0, k = 0; cin >> n; vector<long long int> vv; for (long long int i = 1; i < n + 1; i++) cin >> ar[i], vv.push_back(ar[i]); cin >> m; sort(vv.rbegin(), vv.rend()); while (m--) { cin >> x >> y; a = vv[x - 1]; vector<long long int> ans, v; map<long long int, long long int> mapp; for (long long int i = 0; i < x; i++) { if (vv[i] > a) v.push_back(vv[i]), mapp[vv[i]]++; } z = 0; for (long long int i = 1; i < n + 1; i++) { if (ans.size() == x) break; if (ar[i] == a && z < (x - v.size())) { ans.push_back(a); z++; } else if (mapp[ar[i]] > 0) { mapp[ar[i]]--; ans.push_back(ar[i]); if (mapp[ar[i]] == 0) mapp.erase(ar[i]); } } cout << ans[y - 1] << "\n"; } } inline void runn() { freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); } signed main() { ios::sync_with_stdio(false); cin.tie(NULL); long long int t = 1; for (long long int i = 1; i < t + 1; i++) { solve(); } }
10
CPP
#include <bits/stdc++.h> using namespace std; const long double pi = 2 * acos(0.0); struct arr { long long index, val; }; struct query { long long n, ind, index, ans; }; bool compare(arr a1, arr a2) { if (a1.val == a2.val) return (a1.index < a2.index); return (a1.val > a2.val); } bool compare2(arr a1, arr a2) { return (a1.index < a2.index); } bool compare1(query q1, query q2) { return (q1.n < q2.n); } bool compare3(query q1, query q2) { return (q1.index < q2.index); } int main() { long long n, i; cin >> n; arr A[n]; for (i = 0; i < n; ++i) { cin >> A[i].val; A[i].index = i + 1; } sort(A, A + n, compare); long long m; cin >> m; query q[m]; for (i = 0; i < m; ++i) { cin >> q[i].n >> q[i].ind; q[i].index = i; } sort(q, q + m, compare1); for (i = 0; i < m; ++i) { if (i != 0) { if (q[i].n != q[i - 1].n) { sort(A, A + q[i - 1].n, compare); sort(A, A + q[i].n, compare2); q[i].ans = A[q[i].ind - 1].val; } else q[i].ans = A[q[i].ind - 1].val; } else { sort(A, A + q[i].n, compare2); q[i].ans = A[q[i].ind - 1].val; } } sort(q, q + m, compare3); for (i = 0; i < m; ++i) cout << q[i].ans << "\n"; return 0; }
10
CPP
n = int(input()) a = list(map(int, input().split())) m = int(input()) for i in range(m): d = dict() k, pos = map(int, input().split()) b = a + [] for i in range(k): d[b.index(max(b))] = max(b) b[b.index(max(b))] = 0 print(d[sorted(d.keys())[pos - 1]])
10
PYTHON3
#include <bits/stdc++.h> using namespace std; const int MOD = 1e12; int main() { int n; cin >> n; vector<int> a(n), s; for (int i = 0; i < n; ++i) { cin >> a[i]; } s = a; sort(s.begin(), s.end()); int m; cin >> m; for (int i = 0; i < m; ++i) { int k, pos; cin >> k >> pos; int c = 0; vector<int> ans, st(k); while (c < k) { st[c] = s[n - 1 - c]; ++c; } sort(st.begin(), st.end()); for (int q = 0; q < n; ++q) { bool flag = false; for (int j = 0; j < st.size(); ++j) { if (a[q] == st[j]) { flag = true; st.erase(st.begin() + j); break; } } if (flag && ans.size() < k) { ans.push_back(a[q]); } } cout << ans[pos - 1] << "\n"; } }
10
CPP
#include <bits/stdc++.h> using namespace std; const long long INF = 1e9 + 123, MAXN = 5e5 + 47, MEGAINF = 1e18 + 228; template <class T> inline istream& operator>>(istream& in, vector<T>& a) { for (auto& i : a) in >> i; return in; } template <class T> inline ostream& operator<<(ostream& out, vector<T>& a) { for (auto i : a) out << i << " "; return out; } template <class T, class U> inline istream& operator>>(istream& in, vector<pair<T, U>>& a) { for (auto& i : a) in >> i.first >> i.second; return in; } template <class T, class U> inline ostream& operator<<(ostream& out, vector<pair<T, U>>& a) { for (auto& i : a) out << i.first << " " << i.second << "\n"; return out; } signed main() { setlocale(LC_ALL, "rus"); ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long n; cin >> n; vector<long long> a(n); cin >> a; vector<pair<long long, long long>> p; for (long long i = 0; i < n; ++i) p.push_back({a[i], i}); sort(p.begin(), p.end(), [&](pair<long long, long long> one, pair<long long, long long> two) { if (one.first == two.first) return one.second < two.second; return one.first > two.first; }); long long m; cin >> m; while (m--) { long long k, pos; cin >> k >> pos; --pos; vector<long long> have; for (long long i = 0; i < k; ++i) have.push_back(p[i].second); sort(have.begin(), have.end()); long long ind = have[pos]; cout << a[ind] << "\n"; } }
10
CPP
#include <bits/stdc++.h> long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } long long lcm(long long a, long long b) { return a / gcd(a, b) * b; } const int maxn = 100100; using namespace std; int ans[110][110]; struct node { int nub, pos; } a[110]; bool cmp(node c, node b) { if (c.nub == b.nub) return c.pos < b.pos; return c.nub > b.nub; } bool cmp2(node c, node b) { return c.pos < b.pos; } int main() { int n, m; cin >> n; for (int i = 1; i <= n; ++i) { cin >> a[i].nub; a[i].pos = i; } sort(a + 1, a + 1 + n, cmp); ans[1][1] = a[1].nub; for (int i = 2; i <= n; ++i) { sort(a + 1, a + 1 + i, cmp2); for (int j = 1; j <= i; ++j) { ans[i][j] = a[j].nub; } } cin >> m; for (int i = 1; i <= m; ++i) { int x, pos; cin >> x >> pos; cout << ans[x][pos] << endl; } }
10
CPP
def mergesort(l, r, arr, pos): if r - l == 1: return arr, pos m = (l + r) // 2 arr, pos = mergesort(l, m, arr, pos) arr, pos = mergesort(m, r, arr, pos) c = [0 for i in range(r)] d = [0 for i in range(r)] poi_a = l poi_b = m for i in range(l, r): if poi_a == m: c[i] = arr[poi_b] d[i] = pos[poi_b] poi_b += 1 elif poi_b == r: c[i] = arr[poi_a] d[i] = pos[poi_a] poi_a += 1 elif a[poi_a] > arr[poi_b]: c[i] = arr[poi_a] d[i] = pos[poi_a] poi_a += 1 else: c[i] = arr[poi_b] d[i] = pos[poi_b] poi_b += 1 for i in range(l, r): arr[i] = c[i] pos[i] = d[i] return arr, pos n = int(input()) a = list(map(int, input().split())) p = [i for i in range(n)] temp = a[:] a, p = mergesort(0, n, a, p) for m in range(int(input())): k, pos = map(int, input().split()) j = k while j < n and a[j - 1] == a[j]: j += 1 i = k - 1 l = 1 while i > 0 and a[i - 1] == a[i]: i -= 1 l += 1 m = sorted(p[i:j]) res = sorted(m[:l] + p[:i]) print(temp[res[pos - 1]])
10
PYTHON3
#include <bits/stdc++.h> using namespace std; namespace kotespace { template <class T> class duplet { private: public: T x, y; duplet(){}; duplet(T a, T b) : x(a), y(b){}; bool operator<(const duplet P) const { return (x < P.x || (x == P.x && y < P.y)); } bool operator>(const duplet P) const { return (x > P.x || (x == P.x && y > P.y)); } bool operator==(const duplet P) const { return (x == P.x && y == P.y); } bool operator!=(const duplet P) const { return (x != P.x || y != P.y); } void reverse() { std::swap(x, y); } }; template <class P> istream &operator>>(istream &in, duplet<P> &T) { return (in >> T.x >> T.y); } template <class P> ostream &operator<<(ostream &out, duplet<P> T) { return (out << T.x << " " << T.y); } template <class T> class triplet { private: public: T x, y, z; triplet(){}; triplet(T a, T b, T c) : x(a), y(b), z(c){}; bool operator<(const triplet P) const { return (x < P.x || (x == P.x && y < P.y) || (x == P.x && y == P.y && z < P.z)); } bool operator>(const triplet P) const { return (x > P.x || (x == P.x && y > P.y) || (x == P.x && y == P.y && z > P.z)); } bool operator==(const triplet P) const { return (x == P.x && y == P.y && z == P.z); } bool operator!=(const triplet P) const { return (x != P.x || y != P.y || z != P.z); } void reverse() { std::swap(x, z); } void cycle_right(int a) { if (a == 1) { std::swap(x, y); std::swap(x, z); } if (a == 2) { std::swap(x, z); std::swap(y, x); } } void cycle_left(int a) { if (a == 1) { std::swap(x, z); std::swap(y, x); } if (a == 2) { std::swap(x, y); std::swap(x, z); } } }; template <class P> istream &operator>>(istream &in, triplet<P> &T) { return (in >> T.x >> T.y >> T.z); } template <class P> ostream &operator<<(ostream &out, triplet<P> &T) { return (out << T.x << " " << T.y << " " << T.z); } } // namespace kotespace using namespace kotespace; long long inf = 1000 * 1000 * 1000 + 5; long long inf64 = inf * inf; long long mod = 228228227; vector<duplet<int> > a; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cerr << fixed << setprecision(10); cout << fixed << setprecision(10); srand(time(0)); float START_TIME = clock(); int n; cin >> n; a.resize(n); for (int i = 0; i < n; ++i) { cin >> a[i].x; a[i].x *= -1; a[i].y = i; } sort(a.begin(), a.end()); int k; cin >> k; for (int i = 0; i < k; ++i) { int x, y; cin >> x >> y; vector<duplet<int> > b; for (int j = 0; j < x; ++j) { b.emplace_back(a[j].y, -a[j].x); } sort(b.begin(), b.end()); cout << b[y - 1].y << endl; } cerr << endl << (clock() - START_TIME) / CLOCKS_PER_SEC << " sec." << endl; }
10
CPP
#include <bits/stdc++.h> using namespace std; const int N = 5e3 + 2, mod = 1e9 + 7; void solve() { int n; cin >> n; vector<pair<int, int> > a(n); for (int i = 0; i < n; i++) { cin >> a[i].first; a[i].second = i; } sort(a.begin(), a.end(), [](pair<int, int> i, pair<int, int> j) { if (i.first == j.first) return i.second < j.second; return i.first > j.first; }); int m; cin >> m; while (m--) { int k, pos; cin >> k >> pos; vector<pair<int, int> > v(a.begin(), a.begin() + k); sort(v.begin(), v.end(), [](pair<int, int> i, pair<int, int> j) { return i.second < j.second; }); cout << v[pos - 1].first << '\n'; } } int main() { int tt = 1; for (int tc = 1; tc <= tt; tc++) { solve(); } }
10
CPP
#include <bits/stdc++.h> using namespace std; using ll = int64_t; using ld = long double; void solve(); bool comp(const pair<int64_t, int64_t> &a, const pair<int64_t, int64_t> &b) { if (a.first != b.first) return (a.first < b.first); return (a.second > b.second); } int32_t main() { ios_base::sync_with_stdio(0); cout.tie(0); cin.tie(0); solve(); return 0; } void solve() { int64_t n; cin >> n; pair<int64_t, int64_t> a[n]; for (int64_t i = 0; i < n; i++) { cin >> a[i].first; a[i].second = i; } sort(a, a + n, comp); int64_t q; cin >> q; while (q--) { int64_t x, y; cin >> x >> y; vector<pair<int64_t, int64_t>> v; for (int64_t i = n - 1; i >= n - x; i--) { v.push_back({a[i].second, a[i].first}); } sort((v).begin(), (v).end()); cout << v[y - 1].second << endl; } }
10
CPP
#include <bits/stdc++.h> bool choice_first(std::vector<size_t> a, std::vector<size_t> b) { uint64_t sum_a, sum_b; sum_a = sum_b = 0; for (auto elem : a) { sum_a += elem; } for (auto elem : b) { sum_b += elem; } return sum_a > sum_b || (sum_a == sum_b && a < b); } int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(0); std::cout.tie(0); size_t n, m; std::cin >> n; std::vector<std::vector<std::vector<size_t>>> dp( n + 1, std::vector<std::vector<size_t>>(n + 1)); std::vector<size_t> a(n); for (size_t i = 0; i < n; i++) { std::cin >> a[i]; } std::cin >> m; for (size_t i = 0; i < n; i++) { if (i == 0) { dp[1][i] = {a[0]}; continue; } dp[1][i] = std::max(std::vector<size_t>{a[i]}, dp[1][i - 1]); } for (size_t i = 2; i <= n; i++) { for (size_t j = i - 1; j < n; j++) { if (j == i - 1) { std::vector<size_t> cur = dp[i - 1][j - 1]; cur.push_back(a[j]); dp[i][j] = cur; continue; } std::vector<size_t> first, second; first = dp[i - 1][j - 1]; first.push_back(a[j]); second = dp[i][j - 1]; if (choice_first(first, second)) { dp[i][j] = first; } else { dp[i][j] = second; } } } for (size_t i = 0; i < m; i++) { size_t k, pos; std::cin >> k >> pos; std::cout << dp[k][n - 1][pos - 1] << '\n'; } }
10
CPP
#include <bits/stdc++.h> using namespace std; const int Z = (int)3e3 + 228; const int N = (int)3e5 + 228; const int INF = (int)1e9 + 228; const int MOD = (int)1e9 + 7; int a[N]; map<int, int> cnt; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; vector<int> b; for (int i = 1; i <= n; i++) { cin >> a[i]; b.push_back(a[i]); } sort(b.rbegin(), b.rend()); int m; cin >> m; while (m--) { int k, pos; cin >> k >> pos; multiset<int> mn; map<int, int> q; for (int i = 0; i < k; i++) mn.insert(b[i]), q[b[i]]++; vector<int> ans; for (int i = 1; i <= n; i++) { if (k == 0) break; if (mn.find(a[i]) != mn.end()) { if (a[i] == *mn.begin()) { ans.push_back(a[i]); q[a[i]]--; mn.erase(mn.begin()); k--; } map<int, int> now; for (int j = i + 1; j <= n; j++) now[a[j]]++; bool f = true; for (auto it : mn) if (q[it] > now[it]) f = false; if (f) continue; else { ans.push_back(a[i]); q[a[i]]--; mn.erase(mn.find(a[i])); k--; } } } cout << ans[pos - 1] << "\n"; } return 0; }
10
CPP
#include <bits/stdc++.h> using namespace std; int n, q, arr[101], sr[101]; vector<int> dp[101]; multiset<int> s; int main() { cin >> n; for (long long i = 0; i < n; i++) { cin >> arr[i]; sr[i] = arr[i]; } sort(sr, sr + n, [](int a, int b) { return a > b; }); for (long long i = 1; i <= n; i++) { for (long long j = 0; j < i; j++) { s.insert(sr[j]); } for (long long j = 0; j < n; j++) { if (s.count(arr[j])) { dp[i].push_back(arr[j]); s.erase(s.find(arr[j])); } } } cin >> q; while (q--) { int a, b; cin >> a >> b; cout << dp[a][b - 1] << endl; } return 0; }
10
CPP
#include <bits/stdc++.h> using namespace std; void func() { int n; cin >> n; vector<int> arr(n), acop(n); for (int i = 0; i < n; ++i) { cin >> arr[i]; acop[i] = arr[i]; } sort(acop.begin(), acop.end(), greater<int>()); int q; cin >> q; for (int i = 0; i < q; ++i) { int k, pos, cnt = 0; cin >> k >> pos; for (int i = 0; i < n; ++i) { if (arr[i] > acop[k - 1]) { ++cnt; } } int cnt1 = k - cnt; cnt = 0; for (int i = 0; i < n; ++i) { if (arr[i] >= acop[k - 1]) { if (arr[i] > acop[k - 1]) { ++cnt; } else if (cnt1 > 0 && arr[i] == acop[k - 1]) { ++cnt; --cnt1; } if (cnt == pos) { cout << arr[i] << "\n"; break; } } } } } int main() { int t = 1; int cnt = 0; while (t--) { func(); } return 0; }
10
CPP
#include <bits/stdc++.h> using namespace std; const long long MOD = 1000000007; const long long INF = 1e9 + 5; const double eps = 1e-7; const double PI = acos(-1.0); inline void debug_vi(vector<int> a) { for (long long i = (long long)(0); i < (long long)(a.size()); i++) cout << a[i] << " "; } inline void debug_vll(vector<long long> a) { for (long long i = (long long)(0); i < (long long)(a.size()); i++) cout << a[i] << " "; } inline void print_case(int tn) { cout << "Case #" << tn << ": "; } template <typename T> using minpq = priority_queue<T, vector<T>, greater<T>>; template <typename T> using maxpq = priority_queue<T>; const int N = 2e5 + 5; int a[N], arr[N]; vector<pair<int, int>> vals; int n; struct SegmentTreeNode { int sm; void assignLeaf(int value) { sm = value; } void merge(SegmentTreeNode& left, SegmentTreeNode& right) { sm = left.sm + right.sm; } int getValue() { return sm; } }; template <class T, class V> class SegmentTree { SegmentTreeNode* nodes; int N; public: SegmentTree(T arr[], int N) { this->N = N; nodes = new SegmentTreeNode[getSegmentTreeSize(N)]; buildTree(arr, 1, 0, N - 1); } ~SegmentTree() { delete[] nodes; } V getValue(int pos) { return getValue(1, 0, N - 1, pos); } void update(int index, T value) { update(1, 0, N - 1, index, value); } private: void buildTree(T arr[], int stIndex, int lo, int hi) { if (lo == hi) { nodes[stIndex].assignLeaf(arr[lo]); return; } int left = 2 * stIndex, right = left + 1, mid = lo + (hi - lo) / 2; buildTree(arr, left, lo, mid); buildTree(arr, right, mid + 1, hi); nodes[stIndex].merge(nodes[left], nodes[right]); } int getValue(int stIndex, int left, int right, int pos) { if (left == right) { return left; } int mid = (left + right) / 2; if (nodes[2 * stIndex].getValue() >= pos) return getValue(2 * stIndex, left, mid, pos); return getValue(2 * stIndex + 1, mid + 1, right, pos - nodes[2 * stIndex].getValue()); } int getSegmentTreeSize(int N) { return 4 * N; } void update(int stIndex, int lo, int hi, int index, T value) { if (lo == hi) { nodes[stIndex].assignLeaf(value); return; } int left = 2 * stIndex, right = left + 1, mid = lo + (hi - lo) / 2; if (index <= mid) update(left, lo, mid, index, value); else update(right, mid + 1, hi, index, value); nodes[stIndex].merge(nodes[left], nodes[right]); } }; bool cmp(pair<int, int> a, pair<int, int> b) { if (a.first != b.first) return a.first > b.first; return a.second < b.second; } int main() { std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); clock_t clk = clock(); cin >> n; vals.resize(n); for (long long i = (long long)(0); i < (long long)(n); i++) { cin >> a[i]; vals[i] = {a[i], i}; arr[i] = 1; } sort((vals).begin(), (vals).end(), cmp); SegmentTree<int, int> st(arr, n); int m; cin >> m; vector<tuple<int, int, int>> reqs(m); int k, pos, idx; for (long long i = (long long)(0); i < (long long)(m); i++) { cin >> k >> pos; reqs[i] = make_tuple(k, pos, i); } sort((reqs).begin(), (reqs).end()); vector<int> res(m); int curr = n; for (long long i = (long long)(m - 1); i >= (long long)(0); i--) { tie(k, pos, idx) = reqs[i]; while (curr > k) { st.update(vals[curr - 1].second, 0); curr--; } res[idx] = a[st.getValue(pos)]; } for (int a : res) { cout << a << "\n"; } cerr << "\n" << "Time (in ms): " << double(clock() - clk) * 1000.0 / CLOCKS_PER_SEC << "\n"; return 0; }
10
CPP
#include <bits/stdc++.h> using namespace std; template <typename T1, typename T2, typename T3> struct pair3 { T1 first; T2 second; T3 third; }; template <typename T1, typename T2, typename T3, typename T4> struct pair4 { T1 first; T2 second; T3 third; T4 fourth; }; const long long MOD = 1000000007; const long double PI = acos(-1.0); int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long n, m; cin >> n; vector<long long> ar(n); for (long long i = 0; i < n; ++i) { cin >> ar[i]; } vector<vector<long long>> ans(n + 1); for (long long len = 1; len <= n; ++len) { vector<long long> temp; long long mx = -1, mn = INT_MAX; multiset<long long> st; auto del = [&](long long val) { auto it = temp.end(); --it; while (1) { if (*it == val) { temp.erase(it); break; } it -= 1; } }; for (long long start = 0; start < n; ++start) { if (temp.size() < len) { temp.push_back(ar[start]); st.insert(ar[start]); } else { if (ar[start] > *st.begin()) { del(*st.begin()); st.erase(st.begin()); st.insert(ar[start]); temp.push_back(ar[start]); } } ans[len] = temp; } } cin >> m; long long l, idx; while (m--) { cin >> l >> idx; cout << ans[l][idx - 1] << endl; } return 0; }
10
CPP
#include <bits/stdc++.h> using namespace std; struct eq { long long si, f, s, r; }; bool compare(eq a, eq b) { if (a.f == b.f) return a.s < b.s; return a.f < b.f; } bool comp(eq a, eq b) { return a.si < b.si; } void solve() { long long n; cin >> n; vector<pair<long long, long long> > v; for (long long i = 0; i < n; i++) { long long t; cin >> t; v.push_back({t, -(i + 1)}); } sort(v.begin(), v.end()); long long m; cin >> m; while (m--) { long long k, p; cin >> k >> p; vector<pair<long long, long long> > temp; for (long long i = n - 1; i > n - 1 - k; i--) { temp.push_back({-(v[i].second), v[i].first}); } sort(temp.begin(), temp.end()); cout << temp[p - 1].second << endl; } return; } int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; long long t = 1; while (t--) { solve(); } }
10
CPP
#include <bits/stdc++.h> using namespace std; bool comp(const pair<long long int, long long int> &a, const pair<long long int, long long int> &b) { if (a.first == b.first) { return a.second < b.second; } return a.first > b.first; } int main() { int n; cin >> n; vector<long long int> arr(n); vector<pair<long long int, long long int>> temp(n); for (int i = 0; i < n; i++) { cin >> arr[i]; temp[i] = {arr[i], i}; } sort(temp.begin(), temp.end(), comp); int m, k, pos; cin >> m; while (m--) { cin >> k >> pos; vector<pair<long long int, long long int>> curr; for (int i = 0; i < k; i++) { curr.push_back({temp[i].second, temp[i].first}); } sort(curr.begin(), curr.end()); cout << curr[pos - 1].second << endl; } }
10
CPP
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin >> n; vector<long long> a(n), b(n); for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i < n; i++) { b[i] = a[i]; } sort(a.begin(), a.end(), greater<long long>()); long long m; cin >> m; vector<long long> result; while (m--) { long long k, pos; cin >> k >> pos; map<long long, long long> adj; for (int i = 0; i < k; i++) { adj[a[i]]++; } int ind = 1; long long ans = -1; for (int i = 0; i < n; i++) { auto x = adj.find(b[i]); if (x == adj.end() || (adj[b[i]] == 0)) { continue; } if (ind == pos) { ans = b[i]; break; } adj[b[i]]--; ind++; } cout << ans << endl; } }
10
CPP
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin >> n; long long ar[n]; long long br[n]; for (auto x = 0; x < n; x++) { cin >> ar[x]; br[x] = ar[x]; } sort(br, br + n); long long m; cin >> m; while (m--) { long long pos, k; set<long long> s; cin >> k >> pos; long long bound = br[n - k]; vector<long long> q; for (int x = 0; x < n; x++) { if (bound <= ar[x]) { q.push_back(ar[x]); } } long long sub = q.size() - k; for (int x = q.size() - 1; x >= 0 && sub != 0; x--) { if (bound == q[x]) { q[x] = -1; sub--; } if (sub == 0) { break; } } for (int x = 0; x < q.size(); x++) { if (q[x] == -1) { continue; } pos--; if (pos == 0) cout << q[x] << endl; } } }
10
CPP
#include <bits/stdc++.h> using namespace std; signed main() { long long n; cin >> n; vector<long long> v(n); map<long long, vector<long long>> def; for (long long i = 0; i < n; i++) { cin >> v[i]; def[v[i]].push_back(i); } vector<long long> g; for (auto p : def) { long long a = p.first; vector<long long> b = p.second; for (long long i = 0; i < b.size(); i++) { g.push_back(b[b.size() * 1ll - i - 1]); } } reverse(g.begin(), g.end()); long long m; cin >> m; for (long long i = 0; i < m; i++) { long long k, pos; cin >> k >> pos; vector<long long> f; for (long long j = 0; j < k; j++) { f.push_back(g[j]); } sort(f.begin(), f.end()); cout << v[f[pos - 1]] << "\n"; } return 0; }
10
CPP
n=int(input()) a=[int(x) for x in input().split()] z=a[:] z.sort(reverse=True) an=[[] for i in range(n+1)] an[0]=a[:] for i in range(n): for j in range(len(a)-1,-1,-1) : # print(j,z) if a[j]==z[-1]: del a[j] z.pop() break an[i+1]=a[:] an=an[::-1] for j in range(int(input())): x,y=map(int,input().split()) print(an[x][y-1])
10
PYTHON3
#include <bits/stdc++.h> using namespace std; long long bin_pow(long long a, long long b) { if (b == 0) return 1; if (b % 2 == 0) { long long t = bin_pow(a, b / 2); return t * t % 1000000007; } else return a * bin_pow(a, b - 1) % 1000000007; } int main() { ios::sync_with_stdio(false); cin.tie(0); long long t = 1, n, m, k = 0, x = 0, y = 0, z = 0, sum = 0, l = 0, r = 0, ans = 0, mn = LLONG_MAX, mx = LLONG_MIN; cin >> n; vector<long long> a(n), b(n); for (int i = 0; i < n; i++) cin >> a[i], b[i] = a[i]; sort(b.begin(), b.end()); reverse(b.begin(), b.end()); cin >> m; while (m--) { map<long long, long long> mp, mp1, mp2; cin >> k >> x; vector<long long> c, d; for (int i = 0; i < k; i++) c.push_back(b[i]), mp[b[i]]++; for (int i = 0; i < n; i++) mp1[a[i]]++; reverse(c.begin(), c.end()); c.erase(unique(c.begin(), c.end()), c.end()); l = 0; for (int i = 0; i < n; i++) { if (mp[a[i]] == 0) continue; mp2[a[i]]++; if (a[i] == c[l]) { d.push_back(a[i]); mp[a[i]]--; if (mp[a[i]] == 0) l++; continue; } if (mp[a[i]] > mp1[a[i]] - mp2[a[i]]) { d.push_back(a[i]); mp[a[i]]--; } } ans = d[x - 1]; cout << ans; cout << "\n"; } return 0; }
10
CPP
#include <bits/stdc++.h> using namespace std; vector<int> srr; map<int, int> occ; int main() { ios::sync_with_stdio(false); cin.tie(0); int arr[200], n, m, pj, k, fast = 1, last; cin >> n; for (int i = 1; i <= n; ++i) { cin >> arr[i]; srr.push_back(arr[i]); } sort(srr.begin(), srr.end(), greater<int>()); cin >> m; last = n; while (m--) { vector<int> vec; cin >> k >> pj; for (int i = 0; i < k; ++i) vec.push_back(srr[i]); vector<int> ans; sort(vec.begin(), vec.end()); fast = 1; for (int s = 1; s <= k; ++s) { for (int i = 0; i < k; ++i) { if (vec[i] != -1) { for (int j = fast; j <= last; ++j) { if (arr[j] == vec[i]) { occ.clear(); for (int p = 0; p < k; ++p) { if (vec[p] != -1) occ[vec[p]]++; } for (int p = j; p <= last; ++p) { if (occ[arr[p]]) occ[arr[p]]--; } bool pos = true; for (int p = 0; p < k && pos; ++p) if (vec[p] > 0 && occ[vec[p]] > 0) pos = false; if (pos) fast = j + 1; if (pos) { ans.push_back(vec[i]); vec[i] = -1; i = k; } break; } } } } } cout << ans[pj - 1] << endl; } return 0; }
10
CPP
#include <bits/stdc++.h> using namespace std; int main() { long long int t, n, m, k; cin >> n; vector<int> v[n + 1]; vector<long long int> s; for (int i = 0; i < n; i++) { cin >> t; v[n].push_back(t); s.push_back(t); } sort(s.begin(), s.end()); int l = n - 1, x = 0, y; while (l > 0) { for (int i = v[l + 1].size() - 1; i >= 0; i--) { if (v[l + 1][i] == s[x]) { y = i; break; } } for (int i = 0; i < v[l + 1].size(); i++) { if (i == y) continue; v[l].push_back(v[l + 1][i]); } x++; l--; } cin >> m; for (int i = 0; i < m; i++) { cin >> x >> y; cout << v[x][y - 1] << endl; } }
10
CPP
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> arr(n); set<pair<int, int>> left; for (int i = 0; i < arr.size(); i++) { cin >> arr[i]; left.insert(make_pair(arr[i], i * -1)); } int m; cin >> m; while (m--) { int k, j; cin >> k >> j; j--; set<pair<int, int>> test = left; while (test.size() > k) { auto t = test.begin(); test.erase(t); } vector<pair<int, int>> fil; for (auto a : test) { fil.push_back(make_pair(a.second * -1, a.first)); } sort(fil.begin(), fil.end()); cout << fil[j].second << "\n"; } return 0; }
10
CPP
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") using namespace std; long long N = 1234567891, M = 31; long long n, m, t, k, f, mi = 2e9, x, y, z, ma, x3, x2, y2, l, r, i, j, ans, vv, a2[410000], d[410000], dp[810000]; string s, s2, s3; vector<long long> v, v2, v3; struct pos { long long x, y, z; }; pos a[410000], b[410000]; bool cmp(pos l, pos r) { if (l.x == r.x) return l.y > r.y; return l.x < r.x; } void upd(int l, int r, int x, int ve) { if (l == r) { dp[ve] = 1; return; } int t = (l + r) / 2; if (t >= x) upd(l, t, x, ve * 2); else upd(t + 1, r, x, ve * 2 + 1); dp[ve] = dp[ve * 2] + dp[ve * 2 + 1]; } int sum(int l, int r, int x, int ve) { if (l == r) return l; int t = (l + r) / 2; if (dp[ve * 2] >= x) return sum(l, t, x, ve * 2); return sum(t + 1, r, x - dp[ve * 2], ve * 2 + 1); } int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); cin >> n; for (i = 1; i <= n; i++) { cin >> a[i].x; a2[i] = a[i].x; a[i].y = i; } sort(a + 1, a + n + 1, cmp); cin >> m; for (i = 1; i <= m; i++) { cin >> b[i].x >> b[i].y; b[i].z = i; } sort(b + 1, b + m + 1, cmp); for (i = 1; i <= m; i++) { for (j = b[i - 1].x + 1; j <= b[i].x; j++) { l = a[n - j + 1].y; upd(1, n, l, 1); } d[b[i].z] = a2[sum(1, n, b[i].y, 1)]; } for (i = 1; i <= m; i++) { cout << d[i] << endl; } }
10
CPP
n=int(input()) a=[int(i) for i in input().split()] copy1=a[:] a.sort() m=int(input()) for i in range(m): k,pos=map(int,input().split()) ans=[-1] copy=a[-k:] for i in copy1: if i in copy: copy.pop(copy.index(i)) ans.append(i) print(ans[pos])
10
PYTHON3
n = int(input()) a = [int(i) for i in input().split()] b = sorted(a) b.reverse() m = int(input()) for _ in range(m): k, pos = map(int, input().split()) x = 0 j = 0 d = dict() ans = 0 for i in b[:k]: d[i] = d.get(i, 0) + 1 while x != pos: u = a[j] if u in d: d[u] -= 1 x += 1 if d[u] == 0: del d[u] j += 1 ans = u print(ans)
10
PYTHON3
n=int(input()) a=list(map(int,input().split())) d=[] for i in range(n): d.append([a[i],-i]) d.sort(reverse=True) e=[] for i in range(n): e.append([-d[i][1],d[i][0]]) m=int(input()) f=[] for i in range(m): b,c=map(int,input().split()) f=e[:b] f.sort() print(f[c-1][1])
10
PYTHON3
#include <bits/stdc++.h> using namespace std; int gcd(int a, int b) { while (b) { a %= b; swap(a, b); } return a; } void ct(vector<int> &a) { for (auto &i : a) cout << i << ' '; cout << '\n'; } void ct(vector<pair<int, int>> &a) { for (auto &i : a) cout << i.first << ":" << i.second << ' '; cout << '\n'; } void ct(vector<vector<pair<int, int>>> &a) { for (auto &i : a) ct(i); } void ct(vector<vector<int>> &a) { for (auto &i : a) ct(i); } void ct(vector<set<int>> &a) { for (auto &i : a) { for (auto &j : i) cout << j << ' '; cout << '\n'; } } void ct(set<pair<int, int>> &a) { for (auto &i : a) cout << i.first << ':' << i.second << ' '; cout << '\n'; } void ct(pair<int, int> &a) { cout << a.first << ':' << a.second << '\n'; } void ci(vector<int> &a) { for (int i = 0; i < a.size(); ++i) cin >> a[i]; } void ci(vector<vector<int>> &a) { for (int i = 0; i < a.size(); ++i) ci(a[i]); } void think() {} signed main() { int n, m; cin >> n; vector<pair<int, int>> a; for (int i = 0; i < n; ++i) { int c; cin >> c; a.push_back(make_pair(c, -i)); } sort(a.begin(), a.end()); cin >> m; for (int i = 0; i < m; ++i) { int k, pos; vector<pair<int, int>> ans; cin >> k >> pos; for (int i = n - k; i < n; ++i) { ans.push_back(make_pair(-a[i].second, a[i].first)); } sort(ans.begin(), ans.end()); cout << ans[pos - 1].second << '\n'; ans.clear(); } }
10
CPP
#include <bits/stdc++.h> using namespace std; int n, m; pair<int, int> a[112]; int main() { ios_base::sync_with_stdio(0); cin >> n; for (int i = 0; i < n; i++) { int num; cin >> num; a[i] = {-num, i}; } sort(a, a + n); cin >> m; for (int i = 1; i <= m; i++) { int k, pos; cin >> k >> pos; vector<pair<int, int> > sub; for (int j = 0; j < k; j++) { sub.push_back({a[j].second, -a[j].first}); } sort(sub.begin(), sub.end()); cout << sub[pos - 1].second << "\n"; } }
10
CPP
n=int(input()) import copy mins=[0]*n a=list(map(int,input().split())) m=int(input()) for i in range(m): f=a.copy() k,pos=map(int,input().split()) for l in range(n-k): if mins[l]==0: mins[l]=min(f) for j in range(len(f)-1,-1,-1): if f[j]==mins[l]: f.pop(j) break print(f[pos-1])
10
PYTHON3
#include <bits/stdc++.h> using namespace std; const int maxn = 1e4 + 9; struct node { int x, y; } a[maxn]; int b[maxn]; bool cmp(node a, node b) { return a.x == b.x ? a.y < b.y : a.x > b.x; } map<int, int> A; int main() { int n; scanf("%d", &n); for (int i = 1; i <= n; ++i) { scanf("%d", &a[i].x); b[i] = a[i].x; a[i].y = i; } sort(a + 1, a + 1 + n, cmp); int m; scanf("%d", &m); while (m--) { int k, pos; scanf("%d%d", &k, &pos); for (int i = 1; i <= k; ++i) { A[a[i].y] = 1; } int r = 1; for (int j = 1; j <= n; ++j) { if (A[j]) { if (r == pos) { printf("%d\n", b[j]); break; } r++; } } A.clear(); } return 0; }
10
CPP
#include <bits/stdc++.h> using namespace std; using ll = long long; const int N = 100; int arr[N]; multimap<int, int, greater<int>> l; map<int, int> mp; vector<int> ans[N]; int main() { ios_base::sync_with_stdio(); cin.tie(0); cout.tie(0); int n; scanf("%d", &n); for (int i = 0; i < n; ++i) scanf("%d", arr + i); int m; scanf("%d", &m); for (int i = 0; i < n; ++i) { l.insert(make_pair(arr[i], i)); } for (int i = 0; i < n; ++i) { map<int, int> temp; int j = 0; for (auto t = l.begin(); j <= i; ++j, ++t) { temp[t->second] = t->first; } for (auto t : temp) { ans[i].emplace_back(t.second); } } for (int i = 0; i < m; ++i) { int k, pos; scanf("%d%d", &k, &pos); --k, --pos; printf("%d\n", ans[k][pos]); } }
10
CPP
n = int(input()) b = list(map(int, input().split())) a = [] for i in range(n): a.append([b[i], n - i]) a.sort() a.reverse() p = [] t = [] for i in range(n): t.append(a[i]) d = t.copy() d.sort(key=lambda x: -x[1]) p.append(d) m = int(input()) #print(p) for i in range(m): k, pos = map(int, input().split()) d = p[k - 1].copy() #print(d) print(d[pos - 1][0])
10
PYTHON3
#include <bits/stdc++.h> using namespace std; int bsl(vector<pair<int, int>> &A, int val) { int left = -1; int right = (int)A.size(); while (right - left > 1) { int mid = (left + right) / 2; if (A[mid].first >= val) { right = mid; } else { left = mid; } } return right; } int bsr(vector<pair<int, int>> &A, int val) { int left = 0; int right = (int)A.size() + 1; while (right - left > 1) { int mid = (left + right) / 2; if (A[mid].first <= val) { left = mid; } else { right = mid; } } return left; } int main() { int n; cin >> n; vector<int> N(n); vector<pair<int, int>> A(n); for (int i = 0; i < n; ++i) { cin >> N[i]; A[i] = {N[i], i}; } sort(A.begin(), A.end()); int m; cin >> m; for (int i = 0; i < m; ++i) { int k, pos; cin >> k >> pos; int val = A[n - k].first; set<int> S; int r = bsr(A, val); int l = bsl(A, val); int val1 = n - r - 1; int val2 = k - val1; for (int j = l; j < l + val2; ++j) { S.insert(A[j].second); } for (int j = r + 1; j < n; ++j) { S.insert(A[j].second); } auto itr = S.begin(); advance(itr, pos - 1); cout << N[*itr] << endl; } }
10
CPP
n = int(input()) a = [int(x) for x in input().split()] a_sorted = sorted(a, reverse=True) m = int(input()) for i in range(m): k, pos = [int(x) for x in input().split()] vals = a_sorted[0:k] result = [] for val in a: if val in vals: result.append(val) vals.remove(val) if len(vals) == 0: break print(result[pos - 1])
10
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { long long int n, m, x, i, ma = 0; cin >> n; vector<pair<long long int, long long int>> v1; for (i = 1; i <= n; i++) cin >> x, v1.push_back(make_pair(-x, i)); sort(v1.begin(), v1.end()); cin >> m; while (m--) { long long int k, pos, j = 0; cin >> k >> pos; vector<pair<long long int, long long int>> v; while (j < k) { v.push_back(make_pair(v1[j].second, -v1[j].first)); j++; } sort(v.begin(), v.end()); cout << v[pos - 1].second << endl; } return 0; }
10
CPP
#include <bits/stdc++.h> #pragma GCC optimize("O3") using namespace std; const int inf = 1e9 + 7; bool compA(pair<int, int> a, pair<int, int> b) { if (a.first == b.first) return a.second < b.second; return a.first > b.first; } bool comp(pair<int, int> a, pair<int, int> b) { return a.second < b.second; } void run() { int n, m, k, pos; cin >> n; vector<pair<int, int> > A(n); for (int i = 0; i < n; ++i) { cin >> A[i].first; A[i].second = i; } cin >> m; sort(A.begin(), A.end(), compA); vector<vector<pair<int, int> > > B(n); for (int i = 0; i < n; ++i) { for (int j = 0; j < i + 1; ++j) B[i].push_back(A[j]); sort(B[i].begin(), B[i].end(), comp); } for (int i = 0; i < m; ++i) { cin >> k >> pos; cout << B[--k][--pos].first << '\n'; } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t = 1; for (int i = 0; i < t; ++i) { run(); } return 0; }
10
CPP
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") using namespace std; const long long MOD = 1e9 + 7; const long long mxN = 2e5 + 3; bool cmp(pair<long long, long long> p1, pair<long long, long long> p2) { if (p1.first > p2.first) return true; else if (p1.first == p2.first) { if (p1.second < p2.second) return true; return false; } return false; } void solve() { long long n; cin >> n; long long a[n + 1]; pair<long long, long long> b[n]; for (long long i = 0; i < n; ++i) { cin >> a[i + 1]; b[i].first = a[i + 1]; b[i].second = (i + 1); } sort(b, b + n, cmp); long long m; cin >> m; long long kj, pos_j; vector<vector<long long> > ve(n); for (long long i = 0; i < n; ++i) { for (long long j = i; j < n; ++j) { ve[j].push_back(b[i].second); } } for (long long i = 0; i < n; ++i) sort((ve[i]).begin(), (ve[i]).end()); while (m--) { cin >> kj >> pos_j; kj--; (pos_j)--; cout << a[ve[kj][pos_j]] << "\n"; } } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long nT = 1; for (long long i = (long long)1; i <= (long long)nT; ++i) solve(); return 0; }
10
CPP
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 100; struct node { int id; int num; }; node s[maxn]; int b[maxn]; int num[maxn]; bool cmp(node a, node b) { if (a.num != b.num) return a.num > b.num; else return a.id < b.id; } struct ask { int id; int L = 0; int pos; }; ask A[maxn]; bool cmp2(ask a, ask b) { return a.L < b.L; } int ans[maxn]; int main() { ios::sync_with_stdio(false); int N; cin >> N; for (int i = 1; i <= N; i++) cin >> num[i]; for (int i = 1; i <= N; i++) s[i].num = num[i], s[i].id = i; sort(s + 1, s + 1 + N, cmp); for (int i = 1; i <= N; i++) b[i] = s[i].id; int Q; cin >> Q; for (int i = 1; i <= Q; i++) { cin >> A[i].L; A[i].id = i; cin >> A[i].pos; } sort(A + 1, A + 1 + Q, cmp2); for (int i = 1; i <= Q; i++) { if (A[i].L != A[i - 1].L) sort(b + 1, b + 1 + A[i].L); ans[A[i].id] = b[A[i].pos]; } for (int i = 1; i <= Q; i++) cout << num[ans[i]] << endl; return 0; }
10
CPP
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") using namespace std; mt19937 rnd(time(0)); const long long INF = 1e9; struct Point { Point() { cin >> x; cin >> y; } Point(long double x, long double y) : x(x), y(y) {} long double x, y; }; void solve() { int n, m, k, pos; cin >> n; vector<int> v(n), b(n); for (int i = 0; i < n; i++) { cin >> v[i]; b[i] = v[i]; } sort(b.begin(), b.end()); cin >> m; while (m-- > 0) { cin >> k >> pos; int needDEL = n - k; map<int, int> mp; for (int i = 0; i < needDEL; i++) { mp[b[i]]++; } vector<bool> used(n, 0); for (int i = n - 1; i >= 0 && needDEL != 0; i--) { if (mp[v[i]] != 0) { mp[v[i]]--; used[i] = 1; needDEL--; } } vector<int> newV; for (int i = 0; i < n; i++) { if (!used[i]) { newV.push_back(v[i]); } } cout << newV[pos - 1] << '\n'; } } void jafdj(int aijf, int akfka) { cout << "0" << '\n'; long double o = 1 * 10; long long p = (int)o << 2; return; } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t = 1; while (t--) { solve(); } return 0; }
10
CPP
#include <bits/stdc++.h> using namespace std; long long mod = 1000000007; const long long num = 1000000000; bool check1(pair<long long, long long> a, pair<long long, long long> b) { return a.first == b.first ? (a.second > b.second) : (a.first < b.first); } bool check2(pair<long long, long long> a, pair<long long, long long> b) { return a.second < b.second; } int main() { long long q = 1; while (q--) { long long n, m; cin >> n; vector<pair<long long, long long> > vec(n); for (int i = 0; i < n; i++) { long long a; cin >> a; vec[i].first = a; vec[i].second = i; } cin >> m; sort(vec.begin(), vec.end(), check1); auto v1 = vec; for (int i = 0; i < m; i++) { vec = v1; long long k, p; cin >> k >> p; sort(vec.begin() + n - k, vec.end(), check2); cout << vec[n - k + p - 1].first << endl; ; } } return 0; }
10
CPP
#include <bits/stdc++.h> using namespace std; long long int powMod(long long int x, long long int y) { long long int p = 1; while (y) { if (y % 2) { p = (p * x) % 1000000007; } y /= 2; x = (x * x) % 1000000007; } return p; } long long int invMod(long long int x) { return powMod(x, 1000000007 - 2); } long long int gcd(long long int a, long long int b) { return b == 0 ? a : gcd(b, a % b); } bool sortbysec(const pair<long long int, long long int> &a, const pair<long long int, long long int> &b) { if (a.first == b.first) { return (a.second < b.second); } return (a.first > b.first); } void solve() { long long int n; cin >> n; vector<pair<long long int, long long int> > v; long long int k[n]; for (long long int i = 0; i < n; i++) { cin >> k[i]; v.push_back(make_pair(k[i], i)); } sort(v.begin(), v.end(), sortbysec); long long int m; cin >> m; for (long long int i = 0; i < m; i++) { long long int a, b; cin >> a >> b; long long int ans[a]; for (long long int j = 0; j < a; j++) { ans[j] = v[j].second; } sort(ans, ans + a); cout << k[ans[b - 1]] << '\n'; } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); solve(); return 0; }
10
CPP
#include <bits/stdc++.h> using namespace std; void __print(int x) { cerr << x; } void __print(long x) { cerr << x; } void __print(long long x) { cerr << x; } void __print(unsigned x) { cerr << x; } void __print(unsigned long x) { cerr << x; } void __print(unsigned long long x) { cerr << x; } void __print(float x) { cerr << x; } void __print(double x) { cerr << x; } void __print(long double x) { cerr << x; } void __print(char x) { cerr << '\'' << x << '\''; } void __print(const char *x) { cerr << '\"' << x << '\"'; } void __print(const string &x) { cerr << '\"' << x << '\"'; } void __print(bool x) { cerr << (x ? "true" : "false"); } template <typename T, typename V> void __print(const pair<T, V> &x) { cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}'; } template <typename T> void __print(const T &x) { int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}"; } void _print() { cerr << "]\n"; } template <typename T, typename... V> void _print(T t, V... v) { __print(t); if (sizeof...(v)) cerr << ", "; _print(v...); } const long double PI = acos(-1.0); long long int power(long long int x, long long int y) { long long int res = 1; x = x; while (y > 0) { if (y & 1) res = (res * x); y = y >> 1; x = (x * x); } return res; } long long int power(long long int x, long long int y, long long int p) { long long int res = 1; x = x % p; while (y > 0) { if (y & 1) res = (res * x) % p; y = y >> 1; x = (x * x) % p; } return res; } long long int gcd(long long int a, long long int b) { if (a == 0) return b; return gcd(b % a, a); } bool isPalindrome(string s) { string t = s; reverse(t.begin(), t.end()); return s == t; } void solve() { long long int n; cin >> n; long long int arr[n]; map<long long int, set<long long int> > mm; vector<long long int> v; for (int i = 0; i < n; i++) { cin >> arr[i]; mm[arr[i]].insert(i); v.push_back(arr[i]); } sort(v.begin(), v.end()); ; long long int q; cin >> q; while (q--) { long long int x, y; cin >> x >> y; vector<pair<long long int, long long int> > vec; map<long long int, long long int> temp; long long int i = n - 1; while (vec.size() != x) { long long int key = v[i]; ; vec.push_back(make_pair(*mm[key].begin(), key)); mm[key].erase(*mm[key].begin()); i--; } sort(vec.begin(), vec.end()); ; for (auto it : vec) mm[it.second].insert(it.first); cout << vec[y - 1].second << endl; } } int main() { ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); long long int t = 1; while (t--) { solve(); } return 0; }
10
CPP
n = int(input()) a = list(map(int,input().split())) for i in range(n): a[i] = (a[i],-i) a.sort() m = int(input()) for j in range(m): t = list(map(int, input().split())) k = t[0] p = t[1] print(sorted(a[-k:], key = lambda x: -x[1])[p-1][0])
10
PYTHON3
#include <bits/stdc++.h> using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const int N = 1e5 + 7; const int inf = INT_MAX / 2; const long long INF = LLONG_MAX / 3; const int MOD = 1e9 + 7; const double eps = 1e-6; const string cars[] = {"πŸš—", "πŸš•", "πŸš™"}; signed main() { cout << fixed << setprecision(4); ios::sync_with_stdio(false); cin.tie(); cout.tie(); int n; cin >> n; vector<int> a(n); for (int& x : a) { cin >> x; } auto b = a; sort(a.rbegin(), a.rend()); int q; cin >> q; while (q--) { int k, d; cin >> k >> d; multiset<int> s; for (int i = 0; i < k; i++) { s.insert(s.begin(), a[i]); } int l = 0; for (int i = 0; i < n; i++) { if (s.find(b[i]) != s.end()) { if (++l == d) { cout << b[i] << "\n"; break; } s.erase(s.find(b[i])); } } } return 0; }
10
CPP
n = int(input()) l = [int(j) for j in input().split()] m = int(input()) d = dict() for i in range(n): if l[i] in d: d[l[i]].append(i) else: d[l[i]]=[i] d = sorted(d.items(), reverse =True) # print(d) for que in range(m): k, pos = [int(j) for j in input().split()] min_ = [] i = 0 j = 0 while(k>0): k-=1 min_.append(d[i][1][j]) j+=1 if j==len(d[i][1]): i+=1 j = 0 min_.sort() # print([l[x] for x in min_]) print(l[min_[pos-1]])
10
PYTHON3
#include <bits/stdc++.h> using namespace std; int n, m; bool cmp(pair<int, int> a, pair<int, int> b) { if (a.first != b.first) return a.first > b.first; return a.second < b.second; } bool cmp2(pair<int, int> a, pair<int, int> b) { return a.second < b.second; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; vector<pair<int, int> > v; for (int i = 1; i <= n; i++) { int x; cin >> x; v.push_back({x, i}); } sort(v.begin(), v.end(), cmp); cin >> m; while (m--) { int k, pos; cin >> k >> pos; vector<pair<int, int> > res; for (int i = 0; i < k; i++) { res.push_back(v[i]); } sort(res.begin(), res.end(), cmp2); cout << res[pos - 1].first << '\n'; } return 0; }
10
CPP
#include <bits/stdc++.h> using namespace std; bool comp(pair<long long int, long long int> a, pair<long long int, long long int> b) { if (a.first != b.first) return a.first < b.first; else return a.second > b.second; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int TESTS = 1; while (TESTS--) { long long int n; cin >> n; vector<pair<long long int, long long int> > v; for (long long int i = 0; i < n; i++) { long long int k; cin >> k; v.push_back({k, i}); } sort(v.begin(), v.end(), comp); long long int m; cin >> m; while (m--) { long long int k, pos; cin >> k >> pos; vector<pair<long long int, long long int> > a; for (long long int i = n - k; i < n; i++) a.push_back({v[i].second, v[i].first}); sort(a.begin(), a.end()); cout << a[pos - 1].second << '\n'; } } return 0; }
10
CPP
#include <bits/stdc++.h> using namespace std; vector<long long int> graph[200007]; long long int visited[200007] = {0}; long long int mx = 0, cnt = 0; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long int n, m, i, j; cin >> n; long long int a[n + 10]; vector<pair<long long int, long long int> > v, s, g; vector<long long int> b; for (i = 0; i < n; i++) { cin >> a[i]; s.push_back(make_pair(a[i], i)); } sort(s.begin(), s.end()); for (i = 0; i < n - 1; i++) { if (s[i].first != s[i + 1].first) { g.push_back(make_pair(s[i].first, s[i].second)); for (j = g.size() - 1; j >= 0; j--) { v.push_back(make_pair(g[j].first, g[j].second)); } g.clear(); } else { g.push_back(make_pair(s[i].first, s[i].second)); } } g.push_back(make_pair(s[i].first, s[i].second)); for (j = g.size() - 1; j >= 0; j--) { v.push_back(make_pair(g[j].first, g[j].second)); } cin >> m; while (m--) { long long int k, p; cin >> k >> p; cnt = 0; for (i = n - 1; i >= 0; i--) { cnt++; b.push_back(v[i].second); if (cnt == k) { break; } } sort(b.begin(), b.end()); cout << a[b[p - 1]] << endl; b.clear(); } return 0; }
10
CPP
n = int(input()) a = list(map(int, input().split())) s_a = sorted(a) m = int(input()) req = [] for _ in range(m): req.append(list(map(int, input().split()))) d = dict() for r in req: if r[0] in d.keys(): print(d[r[0]][r[1] - 1]) else: del_indx = [] for e in s_a[:n-r[0]]: for i in reversed(range(n)): if a[i] == e: if i not in del_indx: del_indx.append(i) break new_a = [] for i in range(n): if i not in del_indx: new_a.append(a[i]) d[r[0]] = new_a print(d[r[0]][r[1] - 1])
10
PYTHON3
#include <bits/stdc++.h> using namespace std; bool cmp(pair<int, int> a, pair<int, int> b) { if (a.first != b.first) return a.first < b.first; return a.second > b.second; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; cin >> n; vector<pair<int, int>> a; for (int i = 0; i < n; ++i) { int x; cin >> x; a.emplace_back(x, i); } sort(a.begin(), a.end(), cmp); int m; cin >> m; for (int i = 0; i < m; ++i) { int k, pos; cin >> k >> pos; vector<pair<int, int>> now; for (int i = n - k; i < n; ++i) { now.emplace_back(a[i].second, a[i].first); } sort(now.begin(), now.end()); cout << now[pos - 1].second << "\n"; } }
10
CPP
#include <bits/stdc++.h> #pragma GCC optimize("unroll-loops") #pragma GCC optimize("O3") using namespace std; int a[1000], b[1000]; map<int, bool> mk; int main() { iostream::sync_with_stdio(0); ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; b[i] = a[i]; } sort(a, a + n); int m; cin >> m; for (int i = 0; i < m; i++) { mk.clear(); int pos, k; cin >> k >> pos; vector<int> g; g.clear(); for (int j = n - 1; j >= n - k; j--) { int p; for (int u = 0; u < n; u++) if (!mk[u] && b[u] == a[j]) { p = u; mk[u] = 1; break; } g.push_back(p); } sort(g.begin(), g.end()); cout << b[g[pos - 1]] << "\n"; } }
10
CPP
#include <bits/stdc++.h> using namespace std; void solve(); void fast() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); } template <typename T> istream &operator>>(istream &in, vector<T> &ans) { for (auto &d : ans) in >> d; return in; } template <typename T> ostream &operator<<(ostream &out, vector<T> &ans) { for (auto &d : ans) out << d << " "; return out; } signed main() { fast(); solve(); } struct node { int key; long long y; int sz; node *left, *right; node(int _key) : key(_key) { key = _key; y = rand(); sz = 1; left = nullptr; right = nullptr; } }; int size(node *v) { return (v == nullptr) ? 0 : v->sz; } void upd(node *v) { v->sz = size(v->left) + size(v->right) + 1; } pair<node *, node *> split_key(node *root, int c) { if (root == nullptr) return {nullptr, nullptr}; if (root->key > c) { auto p = split_key(root->left, c); root->left = p.second; upd(root); return {p.first, root}; } else { auto p = split_key(root->right, c); root->right = p.first; upd(root); return {root, p.second}; } } pair<node *, node *> split_size(node *root, int c) { if (root == nullptr) return {nullptr, nullptr}; if (size(root->left) >= c) { auto p = split_size(root->left, c); root->left = p.second; upd(root); return {p.first, root}; } else { auto p = split_size(root->right, c - size(root->left) - 1); root->right = p.first; upd(root); return {root, p.second}; } } node *merge(node *a, node *b) { if (a == nullptr) return b; if (b == nullptr) return a; if (a->y > b->key) { a->right = merge(a->right, b); upd(a); return a; } else { b->left = merge(a, b->left); upd(b); return b; } } node *insert(node *root, int ke) { auto p = split_key(root, ke); return merge(merge(p.first, new node(ke)), p.second); } struct qur { int k, pos, numb; }; bool operator<(qur a, qur b) { return a.k < b.k; } void print(node *root) { if (root == nullptr) return; print(root->left); cout << root->key << " "; print(root->right); } void solve() { int n; cin >> n; srand(time(0)); vector<pair<int, int>> ans(n), pas; for (int i = 0; i < n; ++i) cin >> ans[i].first, ans[i].second = i; int m; cin >> m; vector<qur> kes(m); pas = ans; for (int i = 0; i < m; ++i) cin >> kes[i].k >> kes[i].pos, kes[i].numb = i; auto cmp = [](pair<int, int> a, pair<int, int> b) { if (a.first != b.first) return a.first > b.first; return a.second < b.second; }; sort(kes.begin(), kes.end()); sort(ans.begin(), ans.end(), cmp); int cnt = 0; vector<int> otv(m); node *root = nullptr; for (auto &[k, pos, numb] : kes) { while (cnt < k) root = insert(root, ans[cnt].second), cnt++; auto p = split_size(root, pos - 1); auto c = split_size(p.second, 1); otv[numb] = pas[c.first->key].first; root = merge(p.first, merge(c.first, c.second)); } for (auto &d : otv) cout << d << endl; }
10
CPP
#include <bits/stdc++.h> using namespace std; int a[101]; bool comp(pair<int, int> x, pair<int, int> y) { if (x.first == y.first) { return x.second < y.second; } return x.first > y.first; } bool comp2(pair<int, int> x, pair<int, int> y) { return x.second < y.second; } int d[101][101]; int main() { cin.sync_with_stdio(0); cin.tie(0); cout.tie(NULL); int n; cin >> n; vector<pair<int, int>> v; for (int i = 0; i < n; i++) { cin >> a[i]; v.push_back({a[i], i}); } sort(v.begin(), v.end(), comp); int m; cin >> m; while (m--) { int x, y; cin >> x >> y; vector<pair<int, int>> v2; for (int i = 0; i < x; i++) { v2.push_back(v[i]); } sort(v2.begin(), v2.end(), comp2); cout << v2[y - 1].first << '\n'; } }
10
CPP
n = int(input()) a = list(map(int, input().split())) b = [] for i in range(n): b.append([a[i], -i]) b.sort(reverse=True) for i in range(int(input())): k, pos = map(int, input().split()) ans = 0 z = [] for i in range(k): ans += b[i][0] z.append([-b[i][1], b[i][0]]) z.sort() print(z[pos - 1][1])
10
PYTHON3
#include <bits/stdc++.h> using namespace std; inline void fastio() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); } void solve() { int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; ++i) cin >> a[i]; map<int, vector<int> > mp; for (int i = 0; i < n; ++i) { mp[a[i]].push_back(i); } vector<int> szs(0); vector<int> ind(0); for (auto i : mp) { szs.push_back((int)i.second.size()); ind.push_back((int)i.first); } reverse(szs.begin(), szs.end()); reverse(ind.begin(), ind.end()); vector<int> ps = {szs[0]}; for (int i = 1; i < szs.size(); ++i) { ps.push_back(ps.back() + szs[i]); } int m; cin >> m; while (m--) { int k, pos; cin >> k >> pos; pos--; set<int> psps; int nowind = 0; int nowel = 0; for (int i = 0; i < k; ++i) { psps.insert(mp[ind[nowind]][nowel]); nowel++; if (nowel == mp[ind[nowind]].size()) { nowel = 0; nowind++; } } vector<int> v; for (auto i : psps) { v.push_back(i); } cout << a[v[pos]] << "\n"; } } signed main() { fastio(); solve(); }
10
CPP
#include <bits/stdc++.h> #pragma GCC optimize("-Ofast") using namespace std; bool compare(pair<long long, long long> a, pair<long long, long long> b) { if (a.first != b.first) { return a.first > b.first; } else { return a.second < b.second; } } int32_t main() { long long n; cin >> n; long long arr[n]; vector<pair<long long, long long> > v; for (long long i = 0; i < n; i++) { cin >> arr[i]; v.push_back({arr[i], i}); } sort(v.begin(), v.end(), compare); long long m; cin >> m; while (m--) { long long k, pos; cin >> k >> pos; vector<pair<long long, long long> > cur; for (long long i = 0; i < k; i++) { cur.push_back({v[i].second, v[i].first}); } sort(cur.begin(), cur.end()); cout << cur[pos - 1].second << '\n'; } }
10
CPP
n = int(input()) data = input().split() data1 = [] for i in range(n): data1.append((int(data[i]), i)) data1.sort(key=lambda x: (x[0], -x[1])) for i in range(int(input())): k, pos = map(int, input().split()) temp = sorted(data1[len(data1) - k:], key=lambda x: x[1]) print(temp[pos - 1][0])
10
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; vector<pair<int, int>> v(n); for (int i = 0; i < n; i++) { cin >> v[i].first; v[i].second = i + 1; v[i].first *= -1; } sort(v.begin(), v.end()); int t; cin >> t; for (; t; t--) { int x, y; cin >> x >> y; vector<pair<int, int>> z; for (int i = 0; i < x; i++) { z.push_back({v[i].second, v[i].first}); } sort(z.begin(), z.end()); cout << -z[y - 1].second << "\n"; } }
10
CPP
#include <bits/stdc++.h> using namespace std; int dv(pair<int, int> p1, pair<int, int> p2) { if (p1.first < p2.first) return 0; if (p1.first > p2.first) return 1; if (p1.second > p2.second) return 0; return 1; } int main() { int t, n, m, p, k, a, b, c, l, r; cin >> n; int A[n]; for (int i = 0; i < n; i++) cin >> A[i]; vector<pair<int, int> > v; for (int i = 0; i < n; i++) v.push_back({A[i], i}); sort(v.begin(), v.end(), dv); cin >> m; for (int i = 0; i < m; i++) { vector<int> pos; cin >> k >> p; for (int i = 0; i < k; i++) { pos.push_back(v[i].second); } sort(pos.begin(), pos.end()); cout << A[pos[p - 1]] << endl; } }
10
CPP
#include <bits/stdc++.h> using namespace std; vector<vector<long long>> adj; map<long, bool> vis, viss; vector<long long> rnk, parent, sz; int spf[1000000 + 1]; long long binpow(long long a, long long b, long long m) { a %= m; long long res = 1; while (b > 0) { if (b & 1) res = res * a % m; a = a * a % m; b >>= 1; } return res; } vector<long long> v; bool yg(long long a, long long b) { return (v[a] > v[b] || ((v[a] == v[b]) && a < b)); } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(nullptr); long long t, temp; long long n, m; cin >> n; vector<long long> indx; for (long long i = 0; i < n; i++) { cin >> temp; v.push_back(temp); indx.push_back(i); } sort(indx.begin(), indx.end(), yg); cin >> m; while (m--) { long long k, pos; cin >> k >> pos; vector<long long> arr; for (long long i = 0; i < k; i++) arr.push_back(indx[i]); sort(arr.begin(), arr.end()); cout << v[arr[pos - 1]] << "\n"; } }
10
CPP
#include <bits/stdc++.h> using namespace std; bool kmp(int a, int b) { return a < b; } int main() { int n, m; int x = 0; int y = 0; int z = 0; cin >> n; int a[n]; int d[n][n]; int c[n]; int an[100003]; int k = 0; int p = 0; for (int i = 0; i < n; i++) { cin >> a[i]; c[i] = 1; } cin >> m; int b[m]; int f[m]; for (int i = 0; i < m; i++) { cin >> b[i] >> f[i]; } for (int i = 0; i < n; i++) { p = 0; k = 0; for (int j = 0; j < n; j++) { if (a[j] > p && c[j] == 1) { p = a[j]; x = j; } } c[x] = 0; for (int j = 0; j < x; j++) { if (c[j] == 0) { k++; } } for (int j = 0; j < i + 1; j++) { if (j < k) { d[i][j] = d[i - 1][j]; } else if (j == k) { d[i][j] = p; } else { d[i][j] = d[i - 1][j - 1]; } } } for (int i = 0; i < m; i++) { cout << d[b[i] - 1][f[i] - 1] << endl; } return 0; }
10
CPP
#include <bits/stdc++.h> using namespace std; using ll = long long; using ull = unsigned long long; using ld = long double; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); int getrnd(int l, int r) { return uniform_int_distribution<int>(l, r)(rng); } template <typename T1, typename T2> bool relax(T1& a, const T2& b) { if (a > b) { a = b; return 1; } return 0; } template <typename T1, typename T2> bool strain(T1& a, const T2& b) { if (a < b) { a = b; return 1; } return 0; } void solve() { int n; cin >> n; vector<int> a(n), b(n); for (int i = 0; i < n; ++i) cin >> a[i], b[i] = a[i]; sort(b.rbegin(), b.rend()); int q; cin >> q; while (q--) { int k, pos; cin >> k >> pos; --pos; vector<int> was(n, 0); for (int i = 0; i < n; ++i) { for (int j = 0; j < k; ++j) { if (a[i] == b[j]) was[i] = 1; } } int c = 1; for (int i = k - 2; i >= 0; --i) { if (b[i] == b[i + 1]) ++c; else break; } vector<int> temp; for (int i = 0; i < n; ++i) { if (a[i] == b[k - 1]) { if (c > 0 && was[i]) { temp.emplace_back(a[i]); --c; } } else if (was[i]) { temp.emplace_back(a[i]); } } cout << temp[pos] << '\n'; } } int main() { ios::sync_with_stdio(0); cin.tie(nullptr); cout.tie(nullptr); srand(time(0)); int t = 1; while (t--) solve(); return 0; }
10
CPP
#include <bits/stdc++.h> const int maxn = 1e5 + 5; using namespace std; int n, q; struct node { int x, y, z; } a[maxn], b[maxn], c[maxn]; int tot = 1, ans[maxn]; bool tmp(const node &u, const node &v) { if (u.x != v.x) return u.x > v.x; return u.y < v.y; } bool cc(const node &u, const node &v) { if (u.x != v.x) return u.x < v.x; return u.y < v.y; } bool cmp(const node &u, const node &v) { return u.y < v.y; } int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d", &a[i].x), a[i].y = i; sort(a + 1, a + n + 1, tmp); scanf("%d", &q); for (int i = 1; i <= q; i++) scanf("%d %d", &b[i].x, &b[i].y), b[i].z = i; sort(b + 1, b + q + 1, cc); for (int i = 1; i <= q;) { int m = b[i].x; for (; tot <= m; tot++) c[tot].x = a[tot].x, c[tot].y = a[tot].y; sort(c + 1, c + tot, cmp); for (; b[i].x == m; i++) ans[b[i].z] = c[b[i].y].x; } for (int i = 1; i <= q; i++) printf("%d\n", ans[i]); return 0; }
10
CPP
n = int(input()) arr = [int(i) for i in input().split()] sor = [[arr[i], n - i] for i in range(n)] sor.sort() m = int(input()) for i in range(m): op = [] [q, index] = [int(i) for i in input().split()] for j in range(q): op.append(n - sor[-1-j][1]) op.sort() print(arr[op[index - 1]])
10
PYTHON3
from math import * import os, sys from io import BytesIO input = BytesIO(os.read(0, os.fstat(0).st_size)).readline n = int(input()) a = list(map(int, input().split())) b = [] for i in range(n): b.append((-a[i], i)) b.sort() #print(b) for i in range(int(input())): k, pos = map(int, input().split()) tmp = [] for j in range(k): tmp.append(b[j][1]) tmp.sort() #print(tmp) print(a[tmp[pos - 1]])
10
PYTHON3
#include <bits/stdc++.h> using namespace std; void Update(const long &); long FindSum(const long &); long N, M, K = 0; vector<long> BIT; int main() { cin >> N; vector<pair<long, long>> A(N + 1); vector<long> X(N + 1); for (long i = 1; i <= N; ++i) { cin >> A[i].first; A[i].second = i; X[i] = A[i].first; } cin >> M; vector<pair<pair<long, long>, long>> Q(M); for (long i = 0; i < M; ++i) { cin >> Q[i].first.first >> Q[i].first.second; Q[i].second = i; } sort(A.begin() + 1, A.end(), [&](const pair<long, long> &X, const pair<long, long> &Y) -> bool { if (X.first != Y.first) return X.first > Y.first; else return X.second < Y.second; }); sort(Q.begin(), Q.end()); BIT.resize(N + 1, 0); vector<long> Answer(M); for (long i = 0; i < M; ++i) { while (K < Q[i].first.first) { ++K; Update(A[K].second); } Answer[Q[i].second] = X[FindSum(Q[i].first.second)]; } for (long &x : Answer) cout << x << '\n'; flush(cout); } void Update(const long &I) { for (long i = I; i <= N; i += (i & -i)) ++BIT[i]; } long FindSum(const long &S) { long pos = 0, sum = 0, next; for (long i = 17; i >= 0; --i) { next = pos + (1 << i); if ((next <= N) && (sum + BIT[next] < S)) { pos = next; sum += BIT[pos]; } } return pos + 1; }
10
CPP
n = int(input()) arr = list(map(int, input().split())) arr_sorted = [(arr[i], i) for i in range(n)] arr_sorted.sort(key = lambda el: (el[0], -el[1]), reverse = True) m = int(input()) for req_i in range(m): k, pos = map(int, input().split()) pos -= 1 cur_arr = arr_sorted[:k] cur_arr.sort(key = lambda el: el[1]) print(cur_arr[pos][0])
10
PYTHON3
#include <bits/stdc++.h> using namespace std; vector<bool> sieve(long long n) { vector<bool> prime(n + 1, true); prime[0] = prime[1] = false; for (long long i = 2; i <= n; ++i) { if (prime[i] && (i * i) <= n) for (long long j = i * i; j <= n; j += i) prime[j] = false; } return prime; } long long power(long long a, long long b, long long m = 1000000007) { a %= m; long long res = 1; while (b > 0) { if (b & 1) res = res * a % m; a = a * a % m; b >>= 1; } return res; } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long n; cin >> n; vector<long long> a(n); for (long long i = 0; i < (long long)n; ++i) cin >> a[i]; map<long long, vector<long long> > mp; for (long long i = 0; i < (long long)n; ++i) mp[a[i]].push_back(i); long long t; cin >> t; while (t--) { long long k, idx; cin >> k >> idx; auto it = mp.rbegin(); vector<long long> b; while (k > 0) { vector<long long> temp = it->second; if (k >= (long long)temp.size()) { k -= temp.size(); for (long long i = 0; i < (long long)temp.size(); ++i) { b.push_back(temp[i]); } } else { long long i = 0; while (k--) { b.push_back(temp[i]); i++; } } it++; } sort(b.begin(), b.end()); cout << a[b[idx - 1]] << '\n'; } return 0; }
10
CPP
def f(a): return -a[1] import sys fin = sys.stdin n = int(input()) arr = list(map(int, fin.readline().split())) arr_ind = list() for i in range(n): arr_ind.append([arr[i], -i]) arr_ind.sort() arr_ind.reverse() ans_array = list() for k in range(1, n + 1): ans = arr_ind[:k] ans.sort(key=f) ans_array.append(ans) tests = int(input()) for test in range(tests): k, pos = map(int, input().split()) print(ans_array[k - 1][pos - 1][0])
10
PYTHON3
#include <bits/stdc++.h> #pragma GCC optimize("O3") using namespace std; template <class c> struct rge { c b, e; }; template <class c> rge<c> range(c i, c j) { return rge<c>{i, j}; } template <class c> auto dud(c* x) -> decltype(cerr << *x, 0); template <class c> char dud(...); struct debug { template <class c> debug& operator<<(const c&) { return *this; } }; const long long MOD = 1e9 + 7; const long long N = 1e7 + 10; const long long INF = 1e18 + 10; signed main() { ios_base::sync_with_stdio(false); cin.tie(0); long long n; cin >> n; vector<long long> v(n); map<long long, vector<long long> > mp; for (long long i = 0; i < n; i++) { cin >> v[i]; mp[v[i]].push_back(i); } vector<long long> t = v; sort(t.begin(), t.end()); long long q; cin >> q; while (q--) { long long k, pos; cin >> k >> pos; pos--; vector<pair<long long, long long> > ans; map<long long, long long> cnt; for (long long i = n - k; i < n; i++) { ans.push_back(make_pair(mp[t[i]][cnt[t[i]]], t[i])); cnt[t[i]]++; } sort(ans.begin(), ans.end()); cout << ans[pos].second << endl; } return 0; }
10
CPP
#include <bits/stdc++.h> using namespace std; signed main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cout.precision(20); long long n = 0; cin >> n; deque<long long> posl(n); for (auto& p : posl) cin >> p; map<long long, long long> al; for (auto& p : posl) al[p]++; long long m = 0; cin >> m; for (long long k = 0; k < m; k++) { long long q = 0, pos = 0, sum = 0, num = 0, need = 0; cin >> q >> pos; auto it = al.end(), ed = al.begin(); it--, ed--; for (it; it != ed; it--) { if (sum + it->second < q) sum += it->second; else { need = q - sum; num = it->first; break; } } deque<long long> ans; for (auto& p : posl) { if (p == num && need > 0) ans.push_back(p), need--; else if (p > num) ans.push_back(p); } cout << ans[pos - 1] << "\n"; } return 0; }
10
CPP
n = int(input()) nar = list(map(int, input().split())) m = int(input()) for q in range(m): k, p = list(map(int, input().split())) mar = [] for i in range(k): mar.append(nar[i]) for i in range(k, n): minItem = 0 for j in range(1, k): if mar[j] <= mar[minItem]: minItem = j if nar[i] > mar[minItem]: mar.pop(minItem) mar.append(nar[i]) print(mar[p-1])
10
PYTHON3
import sys # from math import bisect import heapq # from collections import deque # from types import GeneratorType # def bootstrap(func, stack=[]): # def wrapped_function(*args, **kwargs): # if stack: # return func(*args, **kwargs) # else: # call = func(*args, **kwargs) # while True: # if type(call) is GeneratorType: # stack.append(call) # call = next(call) # else: # stack.pop() # if not stack: # break # call = stack[-1].send(call) # return call # return wrapped_function Ri = lambda : [int(x) for x in sys.stdin.readline().split()] ri = lambda : sys.stdin.readline().strip() def input(): return sys.stdin.readline().strip() def list2d(a, b, c): return [[c] * b for i in range(a)] def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)] def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)] def ceil(x, y=1): return int(-(-x // y)) def INT(): return int(input()) def MAP(): return map(int, input().split()) def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)] def Yes(): print('Yes') def No(): print('No') def YES(): print('YES') def NO(): print('NO') INF = 10 ** 18 MOD = 10**9+7 n = int(ri()) ar = Ri() arr= [(ar[i],i) for i in range(n)] arr.sort(key = lambda x: -x[0]) for _ in range(int(ri())): a,b = Ri() temp = [] for i in range(a): temp.append(arr[i][1]) temp.sort() print(ar[temp[b-1]])
10
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { long long int i, j, k, l, m, n; cin >> n; long long int a[n]; vector<long long int> v; for (i = 0; i < n; i++) { cin >> a[i]; v.push_back(a[i]); } sort(v.begin(), v.end()); long long int var; cin >> var; while (var--) { cin >> k >> l; map<long long int, long long int> mp; for (i = n - k; i < n; i++) mp[v[i]]++; long long int it = 0; for (i = 0; i < n; i++) { if (mp[a[i]]) { if (it == l - 1) { cout << a[i] << endl; break; } else it++; mp[a[i]]--; } } } }
10
CPP