In late autumn evening n robots gathered in the cheerful company of friends. Each robot has a unique identifier — an integer from 1 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 the n-th robot says his identifier.
Your task is to determine the k-th identifier to be pronounced.
The first line contains two positive integers n and k (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.
Print the k-th pronounced identifier (assume that the numeration starts from 1).
2 2
1 2
1
4 5
10 4 18 3
4
In the first sample identifiers of robots will be pronounced in the following order: 1, 1, 2. As k = 2, the answer equals to 1.
In the second test case identifiers of robots will be pronounced in the following order: 10, 10, 4, 10, 4, 18, 10, 4, 18, 3. As k = 5, the answer equals to 4.
题意:给你n个数 例如 i1 i2 i3 ....in 按要求排列 形如i1 (i1 i2) (i1 i2 i3).....(i1 i2 i3 i4...in) 要求输出该序列的第k个值
题解:求1~n的前缀和
for循环判断k的位置 输出相应的值
1 #include<bits/stdc++.h> 2 #include<iostream> 3 #include<cstring> 4 #include<cstdio> 5 #include<queue> 6 #include<stack> 7 #include<map> 8 #define ll __int64 9 #define pi acos(-1.0) 10 using namespace std; 11 ll n,k; 12 ll a[100005]; 13 ll sum[100005]; 14 ll ans; 15 int main() 16 { 17 scanf("%I64d %I64d",&n,&k); 18 sum[0]=0; 19 for(int i=1;i<=n;i++) 20 { 21 scanf("%d",&a[i]); 22 sum[i]=sum[i-1]+i; 23 } 24 for(int i=1;i<=n;i++) 25 { 26 if(k<=sum[i]) 27 { 28 ans=i; 29 break; 30 } 31 } 32 printf("%I64d ",a[(k-sum[ans-1])]); 33 return 0; 34 }