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...
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(...
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...
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++...
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; c...
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 <...
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 < ...
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 ...
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 ...
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...
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...
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 ...
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 <...
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, t...
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; ve...
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])) ...
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][...
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 sa...
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 = ...
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]); p...
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>...
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) {...
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; ...
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 (...
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.nu...
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: ...
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 { ret...
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...
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); ...
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...
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 ...
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++) { fo...
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; ...
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_vl...
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 ...
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 =...
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); ...
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>...
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 >>...
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; ...
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...
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); ...
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<i...
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) { ...
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--; ...
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]; strin...
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: ...
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 <...
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 >> po...
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.po...
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] ...
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 ...
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()...
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(ve...
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) ...
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; ...
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() ...
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.firs...
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[ma...
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...
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, lon...
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, 10000000...
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) { cer...
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 <...
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 mi...
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(...
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); ...
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 lo...
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]]: ...
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) { ...
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 >>...
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<<(ostrea...
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_...
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() pr...
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]]...
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...
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...
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+...
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;...
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 >...
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...
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)...
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 = [...
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].fi...
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:...
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 pow...
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....
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> ...
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; ...
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]: ...
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) # ...
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 ...
10
CPP