text stringlengths 49 983k |
|---|
#include <bits/stdc++.h>
using namespace std;
int a[100000], n, k, j, i;
long long ll;
int main() {
cin >> n >> k;
for (i = 1; i <= n; i++) {
cin >> a[i];
if (k > i) k -= i;
}
cout << a[k];
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, k;
scanf("%lld %lld", &n, &k);
vector<int> arr;
arr.push_back(-1);
for (int i = int(0); i < int(n); i++) {
int cur;
scanf("%d", &cur);
arr.push_back(cur);
}
long long des = -1;
for (int i = int(1); i < int(n + 1); i++) {
long long cur = ((long long)i * (i + 1)) / 2;
if (cur >= k) {
des = i;
break;
}
}
long long cur = ((des - 1) * des) / 2;
printf("%d\n", arr[k - cur]);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, k, a, b, c, i, sum, ans;
cin >> n >> k;
long long int arr[n];
for (i = 0; i < n; i++) {
cin >> arr[i];
}
sum = 0;
for (i = 1; i < 100000000; i++) {
if (k > sum + i) {
sum = sum + i;
} else if (sum + i == k) {
ans = i;
break;
} else {
ans = k % sum;
if (sum == 1) ans = 1;
break;
}
}
cout << arr[ans - 1] << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k, i, sum = 0;
cin >> n >> k;
int pre[n], a[n];
for (i = 0; i < n; i++) {
cin >> a[i];
sum += i + 1;
pre[i] = sum;
}
pre[-1] = 0;
for (i = 0; i < n; i++) {
if (k <= pre[i]) {
int t = k - pre[i - 1];
cout << a[t - 1];
return 0;
}
}
return 0;
}
|
#include <bits/stdc++.h>
int arr[100005];
int F(int m) {
int j = 1;
while (m > j) {
m -= j;
j++;
}
return m;
}
int main() {
int n, m;
scanf("%d%d", &n, &m);
for (int i = 0; i < n; i++) scanf("%d", &arr[i]);
int k = F(m);
printf("%d\n", arr[k - 1]);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long unsigned seq[100005], arr[100005];
long long unsigned solve(int ends, long long unsigned k) {
int n = ends;
int beg = 0;
while (beg <= ends) {
int mid = (beg + ends) / 2;
if (seq[mid] == k)
return arr[mid];
else if (seq[mid] > k)
ends = mid - 1;
else
beg = mid + 1;
}
return arr[k - seq[ends]];
}
int main() {
int n;
long long unsigned k;
cin >> n >> k;
seq[0] = 0;
for (int i = 1; i <= n; i++) {
cin >> arr[i];
seq[i] = i + seq[i - 1];
}
cout << solve(n, k) << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, i, ans, k, p, l;
cin >> n >> k;
p = k;
long long int a[n + 2];
for (i = 0; i < n; i++) {
cin >> a[i];
}
k = 2 * k;
k = sqrt(k);
ans = (k * (k + 1)) / 2;
if (ans < p) {
k++;
ans = (k * (k + 1)) / 2;
}
l = ans - p;
cout << a[k - l - 1];
}
|
#include <bits/stdc++.h>
using namespace std;
const long long maxN = 1e6 + 5;
const long long inf = 1e10;
const long long mod = 1e9 + 7;
long long n, k;
long long a[maxN];
int main() {
ios_base::sync_with_stdio(0);
cin >> n >> k;
for (long long i = 1; i <= n; i++) cin >> a[i];
long long res = 1;
for (long long i = 1; i <= maxN; i++) {
long long tmp = (i * (i + 1)) / 2;
if (k <= tmp) {
res = i;
break;
}
}
k -= (res * (res - 1)) / 2;
cout << a[k];
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, k;
cin >> n >> k;
long long arr[n];
for (long long int i = 0; i < n; i++) {
cin >> arr[i];
}
long long ans, d;
for (long long int i = 1; i <= n; i++) {
long long diff = k - (i * (i + 1)) / 2;
if (diff <= 0) {
ans = i - 1;
d = k - (ans * (ans + 1)) / 2;
break;
}
}
if (d == 0) {
cout << arr[ans - 1];
} else {
cout << arr[d - 1];
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, k;
cin >> n >> k;
vector<int> v(n);
for (int i = 0; i < n; i++) cin >> v[i];
long long cur = k;
for (int i = 0; i < n; i++) {
if (cur - (i + 1) <= 0) {
cout << v[cur - 1];
return 0;
}
cur -= i + 1;
}
}
|
#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, k;
cin >> n >> k;
int count = 1;
while (k > count) {
k -= count;
count++;
}
int v;
for (int i = 0; i < k; i++) {
cin >> v;
}
cout << v;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
void bug() { cout << "here\n"; }
template <typename T>
inline T S(T a) {
return a * a;
}
template <class T>
inline string tostring(T a) {
ostringstream os("");
os << a;
return os.str();
}
template <typename T>
inline long long tolong(T a) {
long long res;
istringstream os(a);
os >> res;
return res;
}
template <typename T>
inline T gcd(T a, T b) {
if (b == 0)
return a;
else
return gcd(b, a % b);
}
template <typename T>
inline T bigmod(T a, T b, T m) {
if (b == 0)
return 1;
else if (b % 2 == 0)
return S(bigmod(a, b / 2, m)) % m;
else
return (a % m * bigmod(a, b - 1, m)) % m;
}
const int inf = (int)1e9 + 5;
const long long linf = (long long)1e16 + 5;
const long long modd = (long long)1e9 + 7;
const int mod = 10000007;
bool prime[10000009];
vector<long long> prm;
void seive() {
memset(prime, true, sizeof(prime));
for (long long i = 2; i * i <= 10000009; i++) {
if (prime[i] == true) {
prm.push_back(i);
for (long long j = i * i; j <= 10000009; j += i) prime[j] = false;
}
}
}
void pr(int f) {
if (f == 1)
cout << "YES\n";
else
cout << "NO\n";
}
bool isprime(long long n) {
if (n < 2) return 0;
if (n == 2)
return 1;
else {
for (int i = 2; i * i <= n; i++)
if (n % i == 0) return 0;
}
return 1;
}
long long countSum(long long x) {
long long res = 0;
while (x != 0) {
res += (x % 10);
x /= 10;
}
return res;
}
const int nx = 2e6 + 5;
long long power(long long a, long long b) {
if (b == 0)
return a;
else
return a * power(a, b - 1);
}
const int ms = 2e6;
int a[ms], se[ms], so[ms];
int main() {
ios_base::sync_with_stdio(0);
int n, k;
cin >> n >> k;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
for (int i = 1; i <= n; i++) {
if (k - i > 0) {
k -= i;
continue;
}
cout << a[k];
return 0;
}
}
|
#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
int dx[]{0, 0, 1, -1};
int dy[]{1, -1, 0, 0};
void file() {}
long long fun(long long n) { return n * (n + 1) / 2; }
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, k;
cin >> n >> k;
vector<int> v(n);
for (int i = 0; i < n; i++) cin >> v[i];
long long lo = 0, hi = 1e9;
while (lo <= hi) {
long long mid = (lo + hi) / 2;
if (fun(mid) < k)
lo = mid + 1;
else
hi = mid - 1;
}
k -= fun(lo - 1) + 1;
cout << v[k] << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int N, K;
int id[100001];
int sem;
int main() {
if (fopen("cf670b.in", "r")) {
freopen("cf670b.in", "r", stdin);
freopen("cf670b.out", "w", stdout);
}
cin >> N >> K;
for (int i = 0; i < N; i++) {
cin >> id[i];
}
if (K == 1) {
cout << id[0] << '\n';
return 0;
}
for (int i = 0; i < N; i++) {
sem += i + 1;
if (sem + (i + 2) >= K) {
cout << id[K - sem - 1] << '\n';
return 0;
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int m, n, i, a, k, b, j = 0, l = 0, r = 0, c, ct = 0, pos = 0,
neg = 0, flag = 0, temp = 0, x, y, space,
maxi, ans = 0, ans2 = -100;
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
char ch;
long long int emp[101] = {0}, lang[101] = {0};
string st, st2, st3;
vector<long long int> v, v2;
vector<pair<long long int, long long int> > vp;
queue<pair<long long int, long long int> > q;
cin >> a >> b;
for (i = 0; i < a; i++) {
cin >> temp;
v.push_back(temp);
}
temp = 1;
flag = 1;
while (1) {
temp += flag;
flag++;
if (temp > b) {
temp -= (flag - 1);
break;
}
}
cout << v[b - temp];
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
int v[100010];
long long int i;
int pos;
long long int sum;
scanf("%d %d", &n, &k);
for (i = 1; i <= n; i++) scanf("%d", &v[i]);
i = 0;
sum = 0;
while (sum < k) {
i++;
sum += i;
}
if (sum == k)
printf("%d\n", v[i]);
else
printf("%d", v[i - (sum - k)]);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long long n, k;
cin >> n >> k;
long long i, j, arr[n + 1];
for (i = 1; i <= n; i++) {
cin >> arr[i];
}
for (i = 1; i <= n; i++) {
if ((i * (i + 1)) / 2 >= k) break;
}
i--;
long long req = k - (i * (i + 1)) / 2;
cout << arr[req];
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long n, m, sum, res, flag;
long long a[112345];
int main() {
long long i, j, k, T, cas, x, y, t;
while (scanf("%I64d%I64d", &n, &m) != EOF) {
for (i = 1; i <= n; i++) scanf("%I64d", &a[i]);
sum = 0;
for (i = 1; i <= n; i++) {
sum += i;
if (sum >= m) break;
}
sum -= i;
m -= sum;
printf("%I64d\n", a[m]);
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, k;
cin >> n >> k;
long long int ar[100000];
for (long long int i = 0; i < n; i++) {
cin >> ar[i];
}
long long int i = 1;
while (k > i) {
k -= i;
i++;
}
cout << ar[k - 1] << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const int N = 100010;
int n, k, m;
int a[N];
int main() {
ios_base::sync_with_stdio(0);
cout.tie(0);
cin.tie(0);
cin >> n >> k;
for (int i = 1; i <= n; i++) cin >> a[i];
int cnt = 0;
while (k > 0) {
cnt += 1;
k -= cnt;
}
cout << a[k + cnt];
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
scanf("%d%d", &n, &k);
vector<int> id(n);
for (int i = 0; i < n; i++) scanf("%d", &id[i]);
for (int i = 1; i <= n; i++)
if (i < k) k -= i;
printf("%d\n", id[k - 1]);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long id[100001];
int main(void) {
long long n, k, ans;
cin >> n >> k;
for (int i = 0; i < n; i++) cin >> id[i];
long long start = 1;
long long end = n;
long long exact = 0, mid = -1;
while (start <= end) {
mid = (start + end) / 2;
ans = (mid) * (mid + 1);
if (ans < 2 * k)
start = mid + 1;
else if (ans == 2 * k) {
exact = 1;
break;
} else
end = mid - 1;
}
long long now = -1;
if (start > end) {
now = end;
long long res = k - now * (now + 1) / 2;
cout << id[res - 1];
} else if (exact) {
cout << id[mid - 1];
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int n;
long long res, k;
long long ar[100005];
int main() {
int i, j, t, tc = 1, a, b;
cin >> n >> k;
long long res;
for (i = 0; i < n; i++) cin >> ar[i];
res = 0;
for (i = 1; i <= n; i++) {
res += i;
if (res >= k) break;
}
res = (i * (i - 1) / 2) + 1;
if (res == k) {
cout << ar[0] << endl;
return 0;
}
cout << ar[k - res] << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, k, a[100005], i, j, p, pos;
while (cin >> n >> k) {
for (i = 1; i <= n; i++) cin >> a[i];
for (i = 1; i <= n; i++) {
pos = (i * (i + 1)) / 2;
if (pos >= k) {
j = pos - k;
cout << a[i - j] << endl;
break;
}
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int n, id[100005];
long long cnt, sum;
int main() {
cin >> n >> cnt;
for (int i = 1; i <= n; ++i) cin >> id[i];
for (int i = 1; i <= n; ++i) {
if (cnt - i > 0)
cnt -= i;
else {
cout << id[cnt] << '\n';
return 0;
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 100 * 1000 + 10;
int a[MAX_N];
int main() {
int n, k;
cin >> n >> k;
for (int i = 0; i < n; i++) cin >> a[i];
int u = k;
for (int i = 1; i <= n; i++) {
if (u - i > 0)
u -= i;
else
break;
}
cout << a[u - 1] << endl;
return 0;
}
|
#include <bits/stdc++.h>
void Open() {
freopen(
"txt"
".in",
"r", stdin);
freopen(
"txt"
".out",
"w", stdout);
}
void Close() {
fclose(stdin);
fclose(stdout);
}
using namespace std;
int Read() {
int val = 0, opt = 1;
char ch;
while (!isdigit(ch = getchar()))
if (ch == '-') opt = -1;
while (isdigit(ch)) (val *= 10) += ch - '0', ch = getchar();
return val * opt;
}
int no[100100], n, k, p;
void work() {
cin >> n >> k;
for (int i = 1; i <= n; i++) cin >> no[i];
p = (int)sqrt(2. * k);
while ((p + 1) * (p + 2) < 2 * k) p++;
while ((p + 1) * p >= 2 * k) p--;
k -= p * (p + 1) / 2;
cout << no[k];
}
int main(void) {
work();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
long long robots[100001];
long long N, K;
cin >> N >> K;
for (long i = 0; i < N; i++) {
cin >> robots[i];
}
for (long i = 0; i < N; i++) {
if (K - (i + 1) <= 0) {
cout << robots[K - 1];
return 0;
} else {
K = K - (i + 1);
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
template <typename T>
T gcd(T a, T b) {
return (b != 0 ? gcd(b, a % b) : a);
}
template <typename T>
T lcm(T a, T b) {
return (a / gcd(a, b) * b);
}
template <typename T>
T BigMod(T b, T p, T m) {
if (p == 0) return 1;
if (p % 2 == 0) {
T s = BigMod(b, p / 2, m);
return ((s % m) * (s % m)) % m;
}
return ((b % m) * (BigMod(b, p - 1, m) % m)) % m;
}
template <typename T>
T ModInv(T b, T m) {
return BigMod(b, m - 2, m);
}
template <typename T>
T POW(T B, T P) {
if (P == 0) return 1;
if (P & 1)
return B * POW(B, P - 1);
else
return (POW(B, P / 2) * POW(B, P / 2));
}
template <typename T>
T Swap(T &a, T &b) {
T tmp = a;
a = b;
b = tmp;
}
int Set(int N, int pos) { return N = N | (1 << pos); }
int Reset(int N, int pos) { return N = N & ~(1 << pos); }
bool Check(int N, int pos) { return (bool)(N & (1 << pos)); }
double DEG(double x) { return (180.0 * x) / (2.0 * acos(0.0)); }
double RAD(double x) { return (x * (double)2.0 * acos(0.0)) / (180.0); }
int toInt(string s) {
int sm;
stringstream ss(s);
ss >> sm;
return sm;
}
template <class T>
inline bool readfast(T &x) {
int c = getchar();
int sgn = 1;
while (~c && c < '0' || c > '9') {
if (c == '-') sgn = -1;
c = getchar();
}
for (x = 0; ~c && '0' <= c && c <= '9'; c = getchar()) x = x * 10 + c - '0';
x *= sgn;
return ~c;
}
int R[] = {1, -1, 0, 0, 1, -1, -1, 1};
int C[] = {0, 0, 1, -1, 1, -1, 1, -1};
int KR[] = {-2, -2, -1, 1, 2, 2, -1, 1};
int KC[] = {1, -1, 2, 2, 1, -1, -2, -2};
struct P {
double x, y;
P(double x = 0.0, double y = 0.0) {
this->x = x;
this->y = y;
}
};
P mkv(P ae, P be) { return P(be.x - ae.x, be.y - ae.y); }
double dtp(P ae, P be) { return (ae.x * be.x + ae.y * be.y); }
double crp(P ae, P be) { return (ae.x * be.y - ae.y * be.x); }
double val(P ae) { return sqrt(dtp(ae, ae)); }
P vresize(P ae, double llen) {
double v = val(ae);
return P(ae.x * llen / v, ae.y * llen / v);
}
double ART(P ae, P be) { return crp(ae, be) / 2.0; }
P rot(P ae, double ang) {
return P(ae.x * cos(ang) - ae.y * sin(ang),
ae.y * cos(ang) + ae.x * sin(ang));
}
long long ar[1000006];
int main() {
long long a, b, c, d, h, m, n, p, x, y, i, j, k, l, q, r, t, cnt, sm, tmp;
scanf("%I64d %I64d", &n, &k);
for (i = 1; i <= n; i++) scanf("%I64d", &ar[i]);
cnt = 1;
while (k > cnt) {
k -= cnt;
cnt++;
}
printf("%I64d\n", ar[k]);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const long long MAX = 1e9 + 9;
int dx[8] = {1, 0, 0, -1, 1, -1, 1, -1};
int dy[8] = {0, 1, -1, 0, 1, -1, -1, 1};
int main() {
cin.tie(0);
cout.tie(0);
std::ios::sync_with_stdio(false);
long long n, k;
cin >> n >> k;
vector<long long> v(n);
for (int i = 0; i < n; i++) cin >> v[i];
for (int i = 1; i <= n; i++) {
if (k - i > 0) k -= i;
}
cout << v[k - 1];
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int i, n, k, robot = 0, shout = 0, nextShoutLength = 1, id[100005];
cin >> n >> k;
for (i = 0; i < n; i++) cin >> id[i];
while (shout + nextShoutLength < k)
shout += nextShoutLength, nextShoutLength += 1, ++robot;
k -= robot * (robot + 1) / 2;
cout << id[k - 1] << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 10;
int a[MAXN];
int main() {
int n, k;
scanf("%d%d", &n, &k);
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
}
for (int i = 1; i <= 10000000; i++) {
if (k <= i) break;
k -= i;
}
printf("%d", a[k]);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
struct val {
long long x, y;
};
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
long n, k, a[100002], i;
cin >> n >> k;
for (long i = 0; i < n; i++) cin >> a[i];
for (long i = 1; k - i > 0; i++) k -= i;
cout << a[k - 1];
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
std::ios_base::sync_with_stdio(false);
long long int n, k;
cin >> n >> k;
long long int arr[n];
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
long long int ans = ((int)sqrt(8 * k + 1) - 1) / 2;
ans = (ans * (ans + 1)) / 2;
if (k - ans > 0) {
ans = k - ans;
cout << arr[ans - 1];
} else
cout << arr[((int)sqrt(8 * k + 1) - 1) / 2 - 1];
}
|
#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int n, m;
int a[N];
int main() {
cin >> n >> m;
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
for (int k = 1; k <= n; ++k) {
if (m > k) {
m -= k;
continue;
}
cout << a[m - 1] << endl;
return 0;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, k, i;
scanf("%lld %lld", &n, &k);
long long a[n];
for (i = 1; i <= n; i++) scanf("%lld", &a[i]);
for (i = 1; i <= n; i++) {
if (i >= k) {
cout << a[k] << endl;
break;
} else
k -= i;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
scanf("%d%d", &n, &k);
const int maxn = 1e5 + 10;
int a[maxn];
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
for (int i = 1; i <= n; i++) {
if (k - i > 0)
k -= i;
else
break;
}
printf("%d\n", a[k]);
return 0;
}
|
#include <bits/stdc++.h>
int a[1000000];
int main() {
int n, m;
while (~scanf("%d%d", &n, &m)) {
for (int i = 0; i < n; i++) scanf("%d", &a[i]);
for (int i = 1; i <= n; i++) {
if (m - i > 0)
m -= i;
else
break;
}
printf("%d\n", a[m - 1]);
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, k, c = 1, a = 2;
cin >> n >> k;
long long arr[n];
for (long long i = 0; i < n; i++) {
cin >> arr[i];
}
while (c < k) {
c += a;
a++;
}
a--;
c -= a;
k -= c;
cout << arr[k - 1] << endl;
}
|
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:64000000")
using namespace std;
int n;
int k;
vector<int> a;
int main() {
cin >> n >> k;
a.resize(n + 1);
for (int i = 0; i < n; ++i) {
cin >> a[i + 1];
}
int f = 1;
while (true) {
if (k - f > 0) {
k -= f;
f++;
} else {
break;
}
}
cout << a[k];
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, k, d[100001], i = 0;
cin >> n >> k;
for (int i = 1; i <= n; i++) {
cin >> d[i];
}
while (i * (i + 1) / 2 < k) {
i++;
}
k -= i * (i - 1) / 2;
cout << d[k];
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k, a = 1;
cin >> n >> k;
int arr[n];
for (int i = 0; i < n; i++) cin >> arr[i];
for (int i = 0; i < n; i++) {
a += i;
if (a > k) {
a -= i;
return cout << arr[k - a], 0;
}
}
return cout << arr[k - a], 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
scanf("%d%d", &n, &k);
for (int i = 1; k - i > 0; ++i) k -= i;
for (int i = 1; i <= n; ++i) {
int x;
scanf("%d", &x);
if (i == k) {
printf("%d\n", x);
return 0;
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
double k;
long long arr[100005];
int n;
cin >> n >> k;
for (int i = 1; i <= n; i++) {
cin >> arr[i];
}
double temp = 0.5 * (-1.0 + sqrt(1.0 + 8.0 * k));
temp = (long long)temp;
double lim = temp * .5 * (2.0 + (temp - 1.0));
int index = k - lim;
if (index == 0) index = temp;
cout << arr[index] << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, n, i, sum = 0, k, p = 0, x;
cin >> n >> k;
while (sum < k) {
p++;
sum += p;
}
while (sum > k) {
sum--;
p--;
}
for (i = 1; i <= p; i++) {
cin >> x;
}
for (i = p + 1; i < n; i++) {
cin >> sum;
}
cout << x;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int INF = int(1e9 + 7);
int main() {
std::ios::sync_with_stdio(false);
int n, k;
cin >> n >> k;
int v[n];
for (int i = 0; i < int(n); ++i) {
cin >> v[i];
}
long long x = 1, index = 0, aux = 2;
while (x <= k) {
index++;
x += aux;
aux++;
}
x -= aux - 1;
index--;
if (x == k) {
cout << v[index] << endl;
return 0;
}
index = 0;
while (x < k) {
index++;
x++;
}
cout << v[index - 1] << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
long long int k;
cin >> n >> k;
int i;
vector<int> v(n);
for (i = 0; i < n; i++) {
cin >> v[i];
}
long long int c[n];
c[0] = 1;
for (i = 1; i < n; i++) {
c[i] = c[i - 1] + i + 1;
}
int j;
if (k == 1 && n == 1) {
cout << v[0];
return 0;
}
for (i = 0; i < n - 1; i++) {
if (k == 1) {
j = 0;
break;
} else if (k > c[i] && k <= c[i + 1]) {
j = i + 1 - (c[i + 1] - k);
break;
}
}
if (j == 0) {
cout << v[0] << endl;
} else
cout << v[j] << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, k, i, j, a[100007], m;
while (cin >> n >> k) {
for (i = 1; i <= n; i++) {
cin >> a[i];
}
for (i = 1; i <= n; i++) {
if (k - i > 0) {
k = k - i;
} else {
cout << a[k] << endl;
break;
}
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int n, m, a[100001];
int main() {
cin >> n >> m;
for (int i = 1; i <= n; i++) cin >> a[i];
int i;
for (i = 1; m >= i; i++) m -= i;
if (m == 0)
cout << a[i - 1] << endl;
else
cout << a[m] << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
long long inv(long long a, long long p) {
long long temp = 1;
while (p != 0) {
if (p % 2 == 1) temp = (temp * a) % (int)(1e9 + 7);
a = ((long long)a * a) % (int)(1e9 + 7);
p = p / 2;
}
return temp;
}
int main() {
long long ar[100005];
long long a[100005];
long long n, k;
cin >> n >> k;
for (int i = 1; i <= n; i++) cin >> ar[i];
a[0] = 0;
for (int i = 1; i <= n; i++) a[i] = a[i - 1] + i;
int i;
for (i = 0; i <= n; i++)
if (k <= a[i + 1]) break;
k = k - a[i];
cout << ar[k];
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, k, cor = 0;
cin >> n >> k;
vector<long long> A;
A.resize(n);
for (long long i = 0; i < n; i++) {
cin >> A[i];
}
for (long long i = 1; i <= n + 1; i++) {
if (i * (i + 1) / 2 >= k) {
k = k - (i - 1) * i / 2;
cout << A[k - 1];
return 0;
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
template <class T>
string tostring(T x) {
ostringstream sout;
sout << x;
return sout.str();
}
template <class T>
int toint(T s) {
int v;
istringstream sin(tostring(s));
sin >> v;
return v;
}
vector<string> split(string sentence) {
istringstream iss(sentence);
vector<string> tokens;
copy(istream_iterator<string>(iss), istream_iterator<string>(),
back_inserter<vector<string> >(tokens));
return tokens;
}
string conversion(int a, int b) {
string cambio;
int suma = 0;
int coci = a;
while (coci > 0) {
cambio += tostring(coci % b);
coci = coci / b;
}
return string(cambio.rbegin(), cambio.rend());
}
int GCD(int a, int b) {
if (a % b == 0)
return b;
else
return GCD(b, a % b);
}
int main() {
int n, k;
cin >> n >> k;
vector<int> yay;
for (int a = 0; a < n; a++) {
int aux;
cin >> aux;
yay.push_back(aux);
}
int triangle = 0, num = 0;
while (num < k) {
triangle++;
num += triangle;
}
num -= triangle;
cout << yay[k - (num + 1)];
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int dir[] = {0, 1, 0, -1, 1, 0, -1, 0};
void solve() {
int n, k;
cin >> n >> k;
vector<int> id(n + 1);
for (int i = 1; i <= n; i++) cin >> id[i];
for (int i = 1; i <= n; i++) {
if (i >= k) {
cout << id[k] << endl;
return;
}
k -= i;
}
}
int main() {
ios_base::sync_with_stdio(0);
int t = 1;
for (int cn = 1; cn <= t; cn++) {
solve();
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
long long get(long long n) { return n * (n + 1) / 2; }
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout << fixed << setprecision(9);
long long n, k;
cin >> n >> k;
vector<long long> a(n + 10);
for (long long i = 1; i <= n; ++i) {
cin >> a[i];
}
const long long maxn = 1e6 + 10;
vector<long long> pre(maxn);
for (long long i = 0; i < maxn; ++i) {
pre[i] = get(i);
}
long long index = lower_bound(pre.begin(), pre.end(), k) - pre.begin();
cerr << "index"
" = "
<< (index) << "\n";
;
cerr << "k - pre[index]"
" = "
<< (k - pre[index]) << "\n";
;
if (k == pre[index]) {
cout << a[index] << "\n";
} else {
long long start = index;
long long end = index + 1;
k -= pre[start - 1];
cerr << "k"
" = "
<< (k) << "\n";
;
cerr << "end"
" = "
<< (end) << "\n";
;
for (long long i = 1; i <= end; ++i) {
--k;
if (k == 0) cout << a[i] << "\n";
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main(void) {
int robots, position, answer;
cin >> robots >> position;
int ids[robots];
for (int i = 0; i < robots; i++) cin >> ids[i];
for (int i = 0, current = 0; i < robots; i++) {
current += i + 1;
if (current >= position) {
answer = ids[i - (current - position)];
break;
}
}
cout << answer;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int N = 123456;
long long int a[N];
int main() {
long long int n, k;
cin >> n >> k;
for (int i = 0; i < n; i++) cin >> a[i];
long long int sum = 0;
for (int i = 1; i <= n; i++) {
if (sum + i < k) {
sum += i;
} else
break;
}
k -= sum;
cout << a[k - 1] << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
ll n;
cin >> n;
ll k;
cin >> k;
vector<ll> v(n + 1);
for (ll i = 1; i <= n; ++i) {
cin >> v[i];
}
ll i = 1;
while (k > 0) {
if (i > n) i = 1;
k -= i;
if (k <= 0) {
cout << v[i + k] << endl;
break;
}
i++;
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, k;
cin >> n >> k;
long a[n];
for (int i = 0; i < n; i++) cin >> a[i];
long i = 1;
while (k > i) {
k = k - i;
i++;
}
cout << a[k - 1];
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
long long N, K;
cin >> N >> K;
vector<int> A(N);
for (int i = 0; i < N; ++i) cin >> A[i];
long long i = 1, sum = 0;
for (; sum + i < K; ++i) sum += i;
K -= ((i - 1) * i) / 2;
cout << A[K - 1];
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const long double EPS = 1e-6;
const int INF = (int)(INT_MAX - 100);
const long long mod = (int)(1e+9 + 7);
const int N = (int)(0);
int main() {
int n, k;
cin >> n >> k;
vector<int> v(n);
for (int i = 0; i < n; i++) scanf("%d", &v[i]);
long long x = sqrt(1.0 * (2LL * k + 0.25)) - 0.5 - EPS;
x = x * (x + 1) / 2;
cout << v[k - x - 1];
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return (b == 0 ? a : gcd(b, a % b)); }
long long lcm(long long a, long long b) { return (a * (b / gcd(a, b))); }
long long POWER(long long x, long long y, long long m) {
if (y == 0) return 1;
if (y % 2 == 0) {
long long temp = POWER(x, y / 2, m);
temp *= temp;
temp %= m;
return temp;
}
long long temp = POWER(x, y - 1, m);
temp *= x;
temp %= m;
return temp;
}
long long POWER(long long x, long long y) {
if (y == 0) return 1;
if (y % 2 == 0) {
long long temp = POWER(x, y / 2);
temp *= temp;
return temp;
}
long long temp = POWER(x, y - 1);
temp *= x;
return temp;
}
long long a[100010];
int main() {
ifstream fin("ali");
long long n, k;
cin >> n >> k;
for (int i = 1; i <= n; i++) cin >> a[i];
long long id = 0;
for (long long i = 1; i <= n; i++) {
if ((i * (i + 1)) / 2 >= k) {
id = i;
break;
}
}
if ((id * (id + 1) / 2) == k) {
cout << a[id] << '\n';
return 0;
}
id--;
id = (id * (id + 1)) / 2;
for (int i = 1; i <= n; i++) {
id++;
if (id == k) {
cout << a[i] << '\n';
return 0;
}
}
main();
}
|
#include <bits/stdc++.h>
using namespace std;
long a[(int)1e6 + 6];
long f[(int)1e6 + 6];
int main() {
long n = 10, k = 5;
cin >> n >> k;
for (long i = 0; i < n; i++) scanf("%ld", &a[i]);
long t = 1;
while (k > t) {
k -= t;
t++;
}
cout << a[k - 1];
}
|
#include <bits/stdc++.h>
using namespace std;
int arr[500009];
int main() {
int n, k;
cin >> n >> k;
for (int i = 1; i <= n; i++) {
cin >> arr[i];
}
for (int i = 1; i <= k; i++) {
if (k <= i) break;
k -= i;
}
cout << arr[k] << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007LL;
const long long INF = 0x3f3f3f3f3f3f3f3fLL;
const int iNF = 0x3f3f3f3f;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
long long n, k;
cin >> n >> k;
vector<long long> v;
for (int i = 1; i < n + 1; i += 1) {
long long q;
cin >> q;
v.emplace_back(q);
if (k - i > 0) {
k = k - i;
}
}
cout << v[k - 1] << '\n';
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
long long N, K;
cin >> N >> K;
vector<int> A(N);
for (int i = 0; i < N; i++) cin >> A[i];
long long i = 1;
while ((i * (i + 1)) / 2 < K) i++;
i--;
K -= (i * (i + 1)) / 2;
cout << A[K - 1] << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
long long int cev, n, k;
cin >> n >> k;
for (long long int i = 0;; i++) {
if (i >= k) {
break;
}
k -= i;
}
for (int i = 0; k > i; i++) {
cin >> cev;
}
cout << cev;
}
|
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int N = 1e5;
int main() {
std::ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
int i, k, n, r, g, h, f = 0;
int a[N];
cin >> n >> k;
for (i = 0; i < n; i++) cin >> a[i];
for (i = 1;; i++) {
f = f + i;
if (f >= k) {
g = f - i;
break;
}
}
cout << a[k - g - 1];
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k, x = 0, i = 1;
cin >> n >> k;
vector<int> id(n);
for (auto& x : id) {
cin >> x;
}
while (x < k) {
x += i;
i++;
}
cout << id[k - x + i - 2] << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 7;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
long long n, k;
cin >> n >> k;
long long arr[n + 1];
for (int i = 1; i <= n; i++) cin >> arr[i];
for (int i = 1; i <= n; i++) {
if (k - i > 0) {
k -= i;
continue;
}
cout << arr[k] << endl;
return 0;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int N = 1000 * 100 + 5;
int a[N];
int main() {
int n, k, i;
scanf("%d %d\n", &n, &k);
for (i = 1; i <= n; i++) {
scanf("%d", &a[i]);
}
int j;
j = 1;
while (j * 1ll * (j + 1) / 2 <= k) {
j++;
}
j--;
k -= j * 1ll * (j + 1) / 2;
if (k == 0) {
k = j;
}
printf("%d", a[k]);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
vector<int> v;
int k;
inline long long count(const long long ed) { return (ed * (ed + 1) / 2); }
int bs() {
long long st = 1, ed = v.size(), best = -1;
while (st <= ed) {
long long mid = st + (ed - st) / 2;
if (count(mid) >= k) {
best = mid;
ed = mid - 1;
} else
st = mid + 1;
}
return best;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin >> n >> k;
v.resize(n);
for (int &i : v) {
cin >> i;
}
for (int i = 1; i <= n; ++i) {
if (k > i)
k -= i;
else
return cout << v[k - 1] << '\n', 0;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long a, b, c, d, e, x[100005], i;
cin >> a >> b;
for (i = 1; i <= a; i++) {
cin >> x[i];
}
c = 0;
d = 0;
while (c <= b) {
d++;
c = c + d;
}
c = c - d;
e = b - c;
if (e == 0) e = d - 1;
cout << x[e] << "\n";
}
|
#include <bits/stdc++.h>
using namespace std;
const int dr[] = {1, 0, -1, 0, 1, 1, -1, -1};
const int dc[] = {0, 1, 0, -1, 1, -1, -1, 1};
const double eps = 1e-9;
const int INF = 0x7FFFFFFF;
const long long INFLL = 0x7FFFFFFFFFFFFFFFLL;
const double pi = acos(-1);
template <class T>
T take(queue<T> &O) {
T tmp = O.front();
O.pop();
return tmp;
}
template <class T>
T take(stack<T> &O) {
T tmp = O.top();
O.pop();
return tmp;
}
template <class T>
T take(priority_queue<T> &O) {
T tmp = O.top();
O.pop();
return tmp;
}
template <class T>
inline void getint(T &num) {
bool neg = 0;
num = 0;
char c;
while ((c = getchar_unlocked()) && (!isdigit(c) && c != '-'))
;
if (c == '-') {
neg = 1;
c = getchar_unlocked();
}
do num = num * 10 + c - '0';
while ((c = getchar_unlocked()) && isdigit(c));
if (neg) num = -num;
}
template <class T>
inline bool inRange(T z, T a, T b) {
return a <= z && z <= b;
}
void OPEN(string in = "input.txt", string out = "output.txt") {
freopen(in.c_str(), "r", stdin);
freopen(out.c_str(), "w", stdout);
return;
}
long long n, k;
int main(int argc, const char *argv[]) {
cin >> n >> k;
long long iter = 1LL;
while (iter < k) {
k -= iter;
++iter;
}
int z;
for (int(i) = (0), _t = (k); i < (_t); ++(i)) cin >> z;
cout << z << "\n";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int a[100010];
int main() {
ios::sync_with_stdio(false);
long long n, k;
cin >> n >> k;
for (int i = 0; i < n; i++) cin >> a[i];
long long i = 1;
while (k > i) {
k -= i;
++i;
}
cout << a[k - 1] << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
vector<int> v[200001];
long long visited[200006];
set<long long> set1[200001];
int N;
string s;
long long arr[200005];
long long Pri[3030303];
bool prime[3030303];
int main() {
long long N, M;
long long i, j, k, a, b, l;
cin >> N >> k;
for (i = 1; i < N + 1; i++) cin >> arr[i];
j = 1;
if (k == 1) {
cout << arr[1] << endl;
return 0;
}
while (1) {
a = (j * (j + 1) / 2) + 1;
b = ((j + 1) * (j + 2) / 2);
if (k <= b && k >= a) break;
j++;
}
k = k - ((j * (j + 1)) / 2);
l = k % (j + 2);
cout << arr[l] << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
long long range[1000007];
long long arr[1000007];
long long n, k;
void limit() {
long long sum = 1;
range[1] = sum;
for (long long i = 2; i <= n; i++) {
range[i] = sum + i;
sum += i;
}
}
int main() {
cin >> n >> k;
limit();
for (long long i = 1; i <= n; i++) {
cin >> arr[i];
}
long long start = 0;
for (long long i = 2; i <= n; i++) {
if (k > range[i - 1] && k <= range[i]) {
start = range[i - 1];
break;
}
}
long long res = arr[k - start];
cout << res << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e5 + 10;
int id[MAX], n, k;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n >> k;
for (int(i) = (1); (i) < (n + 1); (i)++) cin >> id[i];
for (int(i) = (1); (i) < (n + 1); (i)++) {
if (k <= i) {
cout << (id[k]) << "\n";
;
return 0;
}
k -= i;
}
}
|
#include <bits/stdc++.h>
using namespace std;
int dx[]{1, -1, 0, 0, 1, -1, 1, -1};
int dy[]{0, 0, 1, -1, 1, -1, -1, 1};
int main() {
long long n, m, g;
string s;
while (cin >> n >> m) {
vector<int> v(n);
for (int i = 0; i < n; i++) cin >> v[i];
int ans = 0;
for (int i = 0; i < n; i++) {
if (m - (i + 1) > 0) {
m -= (i + 1);
} else {
ans = v[m - 1];
break;
}
}
cout << ans << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
std::vector<long long> v;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
;
long long t, n, k, a, b, c, d, s = 0, i, j, flag;
for (long long I = 1; I <= 100000; I++) {
long long x = (I * (I + 1)) / 2;
v.push_back(x);
}
cin >> n >> k;
long long arr[n];
for (i = 0; i < n; i++) cin >> arr[i];
for (i = 0; i < v.size(); i++) {
if (v[i] == k) {
cout << arr[i];
return 0;
;
} else if (v[i] > k) {
b = k - v[i - 1];
cout << arr[b - 1];
return 0;
;
}
}
return 0;
;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k, s, l = 0, a[100010];
cin >> n >> k;
for (int i = 0; i < n; i++) cin >> a[i];
while (k > l) {
l++;
k -= l;
}
if (k)
s = k - 1;
else
s = l - 1;
cout << a[s] << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, k;
cin >> n >> k;
long long nums[n];
for (int i = 0; i < n; i++) {
cin >> nums[i];
}
long long low = 0;
long long high = n;
while (low < high) {
long long mid = (low + high) / 2;
if (2 * k > (mid * (mid + 1))) {
low = mid + 1;
} else if (2 * k < (mid * (mid + 1))) {
high = mid;
} else {
low = mid;
high = mid;
}
}
while (low * (low + 1) >= 2 * k) {
low--;
}
int rem = k - low * (low + 1) / 2;
cout << nums[(rem - 1) % n];
}
|
#include <bits/stdc++.h>
using namespace std;
bool deb = false;
int i;
const int N = 300011;
long long int a[N], b[N];
int main() {
long long int i, j, n, k;
scanf("%lld", &n);
scanf("%lld", &k);
for (i = 1; i < n + 1; ++i) scanf("%lld", &b[i]);
j = 1;
a[1] = 1;
for (i = 2; i < N - 5; ++i) {
j += i;
a[i] = j;
}
long long int id = (lower_bound)(a + 1, a + N - 5, k) - a;
if (a[id] == k)
printf("%lld\n", b[id]);
else {
printf("%lld\n", b[k - a[id - 1]]);
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, k, ns;
cin >> n >> k;
vector<long long> arr(n);
for (int i = 0; i < n; i++) cin >> arr[i];
ns = (long long)(sqrt(1 + 8 * k) - 1) / 2;
k -= (ns * (ns + 1)) / 2;
if (k == 0)
cout << arr[ns - 1];
else
cout << arr[k - 1];
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k, temp = 0;
cin >> n >> k;
int a[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
}
int i;
for (i = 1; i <= n; i++) {
temp += i;
if (temp >= k) break;
}
int gap = temp - k;
cout << a[i - gap - 1];
}
|
#include <bits/stdc++.h>
long long int a[1000005];
int main() {
long long int k, n, i, temp, temp2;
scanf("%lld%lld", &n, &k);
for (i = 1; i <= n; i++) {
scanf("%lld", &a[i]);
}
for (i = 1; i <= n; i++) {
temp = (i * (i + 1)) / 2;
if (temp > k) {
break;
}
}
temp = i - 1;
temp2 = k - ((temp * (temp + 1)) / 2);
if (temp2 == 0) {
printf("%lld\n", a[temp]);
} else {
printf("%lld\n", a[temp2]);
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e5 + 10;
const int MAXN = 1e4 + 10;
const int MOD = 1e9 + 7;
const int inf = 1e9;
const double pi = acos(-1.0);
const double eps = 1e-6;
int a[MAX];
int main() {
ios::sync_with_stdio(false);
int n;
long long k, lo, hi, mi, res;
cin >> n >> k;
for (int i = 0; i < n; i++) cin >> a[i];
lo = 1;
hi = n;
while (lo <= hi) {
mi = (lo + hi) / 2;
if (mi * (mi + 1) >= k * 2) {
res = mi;
hi = mi - 1;
} else
lo = mi + 1;
}
res = res * (res - 1) / 2;
cout << a[k - res - 1];
return 0;
}
|
#include <bits/stdc++.h>
#pragma warning(disable : 4996)
int main() {
int n, k;
scanf("%d %d", &n, &k);
std::vector<int> vec(n);
for (int i = 0; i < n; ++i) scanf("%d", &vec[i]);
for (int i = 0; i < n; ++i) {
if (k <= i + 1) {
break;
} else {
k -= i + 1;
}
}
printf("%d", vec[k - 1]);
}
|
#include <bits/stdc++.h>
using namespace std;
long long ara[100010];
int main() {
long long n, k, i, x;
cin >> n >> k;
for (i = 1; i <= n; i++) {
cin >> ara[i];
}
x = 0;
for (i = 1;; i++) {
if (x + i >= k) {
cout << ara[k - x] << endl;
return 0;
} else
x += i;
}
return 0;
}
|
#include <bits/stdc++.h>
int main() {
int n, i, j, t = 0, m, b, a[200000];
long int k, l, o;
scanf("%d%ld", &n, &k);
for (i = 1; i <= n; i++) scanf("%d", &a[i]);
for (i = 1; k > i; i++) {
k = k - i;
}
printf("%d", a[k]);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k, i;
cin >> n >> k;
int id[n];
for (i = 0; i < n; i++) {
cin >> id[i];
}
for (i = 1; k > i; i++) {
k -= i;
}
cout << id[k - 1];
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
;
long long int n, k;
cin >> n >> k;
int a[n + 1];
for (int i = (1); i <= (n); i++) cin >> a[i];
long long int d = 1 + 8 * k;
long long int x = (long long int)floor(((sqrt(d) - 1) / 2));
if (n == 1)
cout << a[1] << endl;
else {
if ((x * (x + 1)) / 2 == k)
cout << a[x] << endl;
else
cout << a[k - (x * (x + 1)) / 2] << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int chh;
const long long N = 100005;
long long n, k;
long long a[N];
int main() {
long long c;
while (cin >> n >> k) {
for (int i = (1); i <= (n); i++) cin >> a[i];
c = 0;
for (int i = (1); i <= (n); i++) {
if (c + i >= k) {
cout << a[k - c] << '\n';
break;
}
c += i;
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int a[100050];
int main() {
ios::sync_with_stdio(0);
int n, k;
cin >> n >> k;
for (int i = 0; i < n; i++) cin >> a[i];
int p = 1;
while (k > p) {
k -= p;
p++;
}
cout << a[k - 1];
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 123;
const int mod = 1e9 + 7;
const int INF = 1e9 + 1;
const double eps = 1e-9;
const double pi = acos(-1.0);
long long n, a[N], k, ans;
int main() {
ios_base::sync_with_stdio(0);
cin.tie();
cin >> n >> k;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
for (int i = 1;; i++) {
if (ans + i <= k)
ans++;
else
break;
}
for (int i = 1; i <= ans; i++) {
if (k > i)
k -= i;
else {
break;
}
}
cout << a[k];
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long a[100005];
int main() {
long long n, k, tmp;
cin >> n >> k;
for (long long i = 1; i < n + 1; i++) cin >> a[i];
long long cur = 1;
while (1) {
if (k - cur <= 0)
break;
else {
k -= cur;
cur++;
}
}
cout << a[k];
return 0;
}
|
#include <bits/stdc++.h>
int main(void) {
int n, i;
long long int k, a[100001], count;
scanf("%d %I64d", &n, &k);
for (i = 0; i < n; i++) scanf("%I64d", &a[i]);
count = 0;
i = 0;
while (1) {
if (count >= k) break;
count += i + 1;
i++;
}
if (count == k)
printf("%I64d\n", a[i - 1]);
else
printf("%I64d\n", a[i - count + k - 1]);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
int a[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = 0; i < n; i++) {
if ((k - (i + 1)) <= 0) {
cout << a[k - 1];
break;
} else {
k = k - (i + 1);
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
const int mod = 1e9 + 7;
int n, a[N];
long long k;
int main() {
ios_base::sync_with_stdio(0);
cin >> n >> k;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 1; i <= n; i++) {
if (i >= k) {
cout << a[k];
break;
}
k -= i;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
int arr[n];
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
int sum = 0, sum2 = 0;
int i = 1;
while (true) {
if (sum >= k) {
break;
} else
sum += i;
i++;
}
sum2 = sum - k;
cout << arr[i - 1 - sum2 - 1];
return 0;
}
|
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:1024000000,1024000000")
using namespace std;
const double pi = acos(-1.0), eps = 1e-6;
void File() {
freopen("D:\\in.txt", "r", stdin);
freopen("D:\\out.txt", "w", stdout);
}
template <class T>
inline void read(T &x) {
char c = getchar();
x = 0;
while (!isdigit(c)) c = getchar();
while (isdigit(c)) {
x = x * 10 + c - '0';
c = getchar();
}
}
int n, k;
int a[100010];
int main() {
scanf("%d%d", &n, &k);
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
int L = 1, R = n, pos;
while (L <= R) {
int mid = (L + R) / 2;
long long num = (long long)(1 + mid) * (long long)mid / (long long)2;
if (num >= (long long)k)
R = mid - 1, pos = mid;
else
L = mid + 1;
}
k = k - (1 + pos - 1) * (pos - 1) / 2;
printf("%d\n", a[k]);
return 0;
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.