codeforces 670B Game of Robots

来源:互联网 发布:淘宝规则在哪里查看 编辑:程序博客网 时间:2024/06/01 08:48
B - Game of Robots
Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u
Submit Status Practice CodeForces 670B

Description

In late autumn evening n robots gathered in the cheerful company of friends. Each robot has a unique identifier — an integer from 1 to109.

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 the n-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 and k (1 ≤ n ≤ 100 0001 ≤ 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 from 1).

Sample Input

Input
2 21 2
Output
1
Input
4 510 4 18 3
Output
4
题意:n个机器人依次报数,编号为a【1】到a【n】,求第k次所报之数为多少?

1136242673 's source code for B
Memory: 2612 KB Time: 46 MSLanguage: GNU G++ 4.9.2 Result: AcceptedPublic:  
Select All
1234567891011121314151617181920212223242526272829303132333435
#include<iostream>#include<algorithm>#include<cstdio>#include<cstring>#include<cmath>#include<queue>#include<cctype>#define max(a,b)(a>b?a:b)#define min(a,b)(a<b?a:b)#define INF 0x3f3f3f3ftypedef long long ll;using namespace std;#define N 110000int a[N];int main(){    int n,i;    ll k;    while(scanf("%d%I64d",&n,&k)!=EOF)    {         for(i=1;i<=n;i++)            scanf("%d",&a[i]);         for(i=1;i<=n;i++)         {            if(k<=i)                break;            k=k-i;         }         printf("%d\n",a[k]);    }    return 0;}



0 0
原创粉丝点击