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 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.

Input

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.

Output

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

Examples
Input
2 2
1 2
Output
1
Input
4 5
10 4 18 3
Output
4
Note

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的位置  输出相应的值

 #include<bits/stdc++.h>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<queue>
#include<stack>
#include<map>
#define ll __int64
#define pi acos(-1.0)
using namespace std;
ll n,k;
ll a[];
ll sum[];
ll ans;
int main()
{
scanf("%I64d %I64d",&n,&k);
sum[]=;
for(int i=;i<=n;i++)
{
scanf("%d",&a[i]);
sum[i]=sum[i-]+i;
}
for(int i=;i<=n;i++)
{
if(k<=sum[i])
{
ans=i;
break;
}
}
printf("%I64d\n",a[(k-sum[ans-])]);
return ;
}

Codeforces Round #350 (Div. 2) B的更多相关文章

  1. Codeforces Round #350 (Div. 2) E. Correct Bracket Sequence Editor 模拟

    题目链接: http://codeforces.com/contest/670/problem/E 题解: 用STL的list和stack模拟的,没想到跑的还挺快. 代码: #include<i ...

  2. Codeforces Round #350 (Div. 2) D2. Magic Powder - 2

    题目链接: http://codeforces.com/contest/670/problem/D2 题解: 二分答案. #include<iostream> #include<cs ...

  3. Codeforces Round #350 (Div. 2) E. Correct Bracket Sequence Editor (链表)

    题目链接:http://codeforces.com/contest/670/problem/E 给你n长度的括号字符,m个操作,光标初始位置是p,'D'操作表示删除当前光标所在的字符对应的括号字符以 ...

  4. Codeforces Round #350 (Div. 2)解题报告

    codeforces 670A. Holidays 题目链接: http://codeforces.com/contest/670/problem/A 题意: A. Holidays On the p ...

  5. Codeforces Round #350 (Div. 2) E. Correct Bracket Sequence Editor 栈 链表

    E. Correct Bracket Sequence Editor 题目连接: http://www.codeforces.com/contest/670/problem/E Description ...

  6. Codeforces Round #350 (Div. 2) D1. Magic Powder - 1 二分

    D1. Magic Powder - 1 题目连接: http://www.codeforces.com/contest/670/problem/D1 Description This problem ...

  7. Codeforces Round #350 (Div. 2) C. Cinema 水题

    C. Cinema 题目连接: http://www.codeforces.com/contest/670/problem/C Description Moscow is hosting a majo ...

  8. Codeforces Round #350 (Div. 2) B. Game of Robots 水题

    B. Game of Robots 题目连接: http://www.codeforces.com/contest/670/problem/B Description In late autumn e ...

  9. Codeforces Round #350 (Div. 2) A. Holidays 水题

    A. Holidays 题目连接: http://www.codeforces.com/contest/670/problem/A Description On the planet Mars a y ...

  10. Codeforces Round #350 (Div. 2) E 思维模拟

    给出一个合法的括号串 有LRD三种操作 LR分别是左右移动当前位置 且合法 D为删除这个括号和里面的所有 当删除完成后 位置向右移动 如果不能移动 就向左 比赛都是很久远的事情了 写这道题也是一时兴起 ...

随机推荐

  1. flask(列表实现)

    在 index/views.py 中定义视图函数 在查询的时候,如果用户分类id传0,则不添加分类查询条件 @index_blu.route('/newslist') def get_news_lis ...

  2. CentOs安装Mysql和配置初始密码

    mysql官网yum安装教程,地址:https://dev.mysql.com/doc/mysql-yum-repo-quick-guide/en/#repo-qg-yum-fresh-install ...

  3. 【转】iOS库 .a与.framework区别

    转自:http://blog.csdn.net/lvxiangan/article/details/43115131 一.什么是库? 库是共享程序代码的方式,一般分为静态库和动态库. 二.静态库与动态 ...

  4. 第6模块 web框架口述题

    状态码如200 OK,以3位数字和原因 成.数字中的 一位指定了响应 别,后两位无分 .响应 别有以下5种. 重定向:客户端像服务器端发送请求,服务器告诉客户端你去重定向(状态码302,响应头loca ...

  5. 数据迁移的应用场景与解决方案Hamal

    本文来自网易云社区 作者:马进 跑男热播,作为兄弟团忠实粉丝,笔者也是一到周五就如打鸡血乐不思蜀. 看着银幕中一众演员搞怪搞笑的浮夸演技,也时常感慨,这样一部看似简单真情流露的真人秀,必然饱含了许许多 ...

  6. 【jQuery】 实用 js

    [jQuery] 实用 js 1. int 处理 parseInt(") // int 转换 isNaN(page) // 判断是否是int类型 2. string 处理 // C# str ...

  7. 「日常训练」 Mike and Frog (CFR305D2C)

    题意与分析 (Codeforces 548C) 我开始以为是一条数学题,死活不知道怎么做,无奈看题解,才知这是一条暴力,思维江化了- - 题意大概是这样的: 两个东西的初始高度分别为h1,h2&quo ...

  8. 树莓派的WIFI配置

    参考网址: http://www.cnblogs.com/iusmile/archive/2013/03/30/2991139.html http://my.oschina.net/pikeman/b ...

  9. NO3——BFS

    #include <stdio.h> #include <string.h> #include <queue> using namespace std; struc ...

  10. rcnn caffe matlab 配置完成 14.04 cuda 7.0

    http://blog.csdn.net/real_myth/article/details/42672381 各种痛苦.实验室网速还是龟速. 莫名其妙的错误. gcc还降级到4.7,opencv 3 ...