Codeforces Round #350 (Div. 2) - B. Game of Robots (STL)

来源:互联网 发布:中国社会发展数据库 编辑:程序博客网 时间:2024/05/29 11:06
B. Game of Robots
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

In late autumn evening n robots gathered in the cheerful company of friends. Each robot has a unique identifier — an integer from1 to 109.

At some moment, robots decided to play the game "Snowball". Below there are the rules of this game. First, all robots stand in a row. Then the first robot says his identifier. After that the second robot says the identifier of the first robot and then says his own identifier. Then the third robot says the identifier of the first robot, then says the identifier of the second robot and after that says his own. This process continues from left to right until then-th robot says his identifier.

Your task is to determine the k-th identifier to be pronounced.

Input

The first line contains two positive integers n andk (1 ≤ n ≤ 100 000,1 ≤ k ≤ min(2·109, n·(n + 1) / 2).

The second line contains the sequence id1, id2, ..., idn (1 ≤ idi ≤ 109) — identifiers of roborts. It is guaranteed that all identifiers are different.

Output

Print the k-th pronounced identifier (assume that the numeration starts from1).

Examples
Input
2 21 2
Output
1
Input
4 510 4 18 3
Output
4
Note

水题:
题意:
有n 个机器人。
第一个机器人会报自己id,
第二个机器人会先报第一个,在报自己的
第三个 会报第一个报第二个 报第三个。




以此类推。
问第k个数是多少!
直接找到k 在那个sum 中 (其中sum[i]表示前1 + 2 + 3 。。。 + i)
然后做差输出第几个id 即可!
#include<cstdio>#include<cstring>#include<algorithm>using namespace std;typedef long long ll;const int maxn = 100000 + 10;ll sum[maxn];int a[maxn];void init(){    for (int i = 1; i <= maxn; ++i)sum[i] = sum[i-1] + i;}int main(){    init();    int n,k;    while(scanf("%d%d",&n,&k) == 2){        for (int i = 1; i <= n; ++i)scanf("%d",&a[i]);        int m = lower_bound(sum,sum+maxn,k) - sum;        m = k - sum[m-1];        printf("%d\n",a[m]);    }    return 0;}


0 0