XXI Berland Annual Fair is coming really soon! Traditionally fair consists of nnbooths, arranged in a circle. The booths are numbered 11 through nn clockwise with nnbeing adjacent to 11. The ii-th booths sells some candies for the price of aiai burles per item. Each booth has an unlimited supply of candies.

Polycarp has decided to spend at most TT burles at the fair. However, he has some plan in mind for his path across the booths:

  • at first, he visits booth number 11;
  • if he has enough burles to buy exactly one candy from the current booth, then he buys it immediately;
  • then he proceeds to the next booth in the clockwise order (regardless of if he bought a candy or not).

Polycarp's money is finite, thus the process will end once he can no longer buy candy at any booth.

Calculate the number of candies Polycarp will buy.

Input

The first line contains two integers nn and TT (1≤n≤2⋅1051≤n≤2⋅105, 1≤T≤10181≤T≤1018) — the number of booths at the fair and the initial amount of burles Polycarp has.

The second line contains nn integers a1,a2,…,ana1,a2,…,an (1≤ai≤1091≤ai≤109) — the price of the single candy at booth number ii.

Output

Print a single integer — the total number of candies Polycarp will buy.

Examples

Input
3 38
5 2 5
Output
10
Input
5 21
2 4 100 2 6
Output
6

Note

Let's consider the first example. Here are Polycarp's moves until he runs out of money:

  1. Booth 11, buys candy for 55, T=33T=33;
  2. Booth 22, buys candy for 22, T=31T=31;
  3. Booth 33, buys candy for 55, T=26T=26;
  4. Booth 11, buys candy for 55, T=21T=21;
  5. Booth 22, buys candy for 22, T=19T=19;
  6. Booth 33, buys candy for 55, T=14T=14;
  7. Booth 11, buys candy for 55, T=9T=9;
  8. Booth 22, buys candy for 22, T=7T=7;
  9. Booth 33, buys candy for 55, T=2T=2;
  10. Booth 11, buys no candy, not enough money;
  11. Booth 22, buys candy for 22, T=0T=0.

No candy can be bought later. The total number of candies bought is 1010.

In the second example he has 11 burle left at the end of his path, no candy can be bought with this amount.

题目大意:

n种糖果围成一圈,每种糖果每个ai元。初始时你有t元,接着你从1开始疯狂地绕圈。一旦你发现有糖果能买,你就买一个。直到一个糖果都买不起。问最后你买了多少个糖果。

稍微带点技巧的模拟。

若一个周期的和小于剩余的t,就直接买几个周期,不必一个个模拟。

然后遇到买不起的则将他从周期中删除。

注意用long long

#include<cstdio>
#include<queue>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<string>
#include<iostream>
#define lol long long
#define maxn 200000 using namespace std; lol a[maxn+]; int main()
{
lol n,t;
scanf("%lld%lld",&n,&t);
lol sum=;
for(int i=;i<=n;i++)
{
scanf("%lld",a+i);
sum+=a[i];
} lol ans=;
lol cur=n;
lol num=n;
while()
{
ans+=(t/sum)*num;
t=t%sum;
//printf("%lld\n",t);
for(int i=;;i++)
{
//printf("%lld %lld\n",a[(cur+i-1)%n+1],t);
if(a[(cur+i-)%n+]==-)
continue;
if(a[(cur+i-)%n+]>t)
{
sum-=a[(cur+i-)%n+];
num--;
a[(cur+i-)%n+]=-;
cur=(cur+i-)%n+;
break;
}
t-=a[(cur+i-)%n+];
ans++;
} if(num==)
break;
}
printf("%lld\n",ans); return ;
}

好久没有更新博客了。

曾经被炒上天的ACM,如今却有些人走茶凉的味道。

正确的事是要坚持的。

CodeForces - 1073D Berland Fair的更多相关文章

  1. codeforces 897A Scarborough Fair 暴力签到

    codeforces 897A Scarborough Fair 题目链接: http://codeforces.com/problemset/problem/897/A 思路: 暴力大法好 代码: ...

  2. CodeForce edu round 53 Div 2. D:Berland Fair

    D. Berland Fair time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...

  3. codeforces1073d Berland Fair 思维(暴力删除)

    题目传送门 题目大意:一圈人围起来卖糖果,标号从1-n,每个位置的糖果都有自己的价格,一个人拿着钱从q开始走,能买则买,不能买则走到下一家,问最多能买多少件物品. 思路:此题的关键是不能买则走到下一家 ...

  4. [Codeforces 1005F]Berland and the Shortest Paths(最短路树+dfs)

    [Codeforces 1005F]Berland and the Shortest Paths(最短路树+dfs) 题面 题意:给你一个无向图,1为起点,求生成树让起点到其他个点的距离最小,距离最小 ...

  5. Codeforces 1073D:Berland Fair(模拟)

    time limit per test: 2 secondsmemory limit per test: 256 megabytesinput: standard inputoutput: stand ...

  6. 【Codeforces 1073D】Berland Fair

    [链接] 我是链接,点我呀:) [题意] 题意 [题解] 我们可以从左到右枚举一轮. 定义一个cost表示这一轮花费的钱数 如果cost+a[i]<=T那么就可以买它,并且买下它(模拟题目要求) ...

  7. [codeforces][Educational Codeforces Round 53 (Rated for Div. 2)D. Berland Fair]

    http://codeforces.com/problemset/problem/1073/D 题目大意:有n个物品(n<2e5)围成一个圈,你有t(t<1e18)元,每次经过物品i,如果 ...

  8. Educational Codeforces Round 53 (Rated for Div. 2) D. Berland Fair

    题意:一个人  有T块钱 有一圈商店 分别出售 不同价格的东西  每次经过商店只能买一个  并且如果钱够就必须买 这个人一定是从1号店开始的!(比赛的时候读错了题,以为随意起点...)问可以买多少个 ...

  9. CodeForces 567B Berland National Library

    Description Berland National Library has recently been built in the capital of Berland. In addition, ...

随机推荐

  1. 【故障公告】docker swarm 集群问题造成新版博客后台故障

    非常抱歉,今天下午 16:55~17:05 左右,由于 docker swarm 集群的突发不稳定问题造成新版博客后台(目前处于灰度发布阶段)无法正常使用,由此给您带来麻烦,请您谅解. 出故障期时,新 ...

  2. 配置k8s集群context-rbac实践

    说明 在openshift环境中,可以通过oc project {project_name}命令来切换project,那么在k8s中式如何切换namespace的呢?(ocp的project即相当于k ...

  3. HTTP基础及telnet简单命令

    一.HTTP概况 20世纪90年代初期,一个主要的新兴应用即万维网(World Wide Web)登上了舞台.Web是一个引起公众注意的因特网应用.Web的应用层协议是超文本传输协议(HTTP),它是 ...

  4. 新闻实时分析系统-Hadoop2.X分布式集群部署

    (一)hadoop2.x版本下载及安装 Hadoop 版本选择目前主要基于三个厂商(国外)如下所示: 1.基于Apache厂商的最原始的hadoop版本, 所有发行版均基于这个版本进行改进. 2.基于 ...

  5. https的安装(基于阿里云)

    背景介绍:首先我的服务器在是阿里云的云服务器,web服务器使用的是nginx 进入到阿里云的ssl证书的管理界面,按需选择套餐后进行申请,申请完成后进行补全操作,最后是变成如下界面点击--下载进行证书 ...

  6. 3、Docker 基础安装和基础使用 二

    Docker 网络 启动了nginx容器,但却不知道从哪里进行访问nginx. 启动nginx容器,并附加网络映射 在启动nginx容器的时候,增加一个-P大写的P的参数 表示随机映射一个端口 [ro ...

  7. drf过滤器、分页器、筛选器的应用

    一.drf 提供的过滤器(ordering) views.py from rest_framework.generics import ListAPIView from . import models ...

  8. 第二章 Unity Shader基础

    [TOC] 1. Unity Shader 的基础: ShaderLab 学习和编写着色器的过程一直是一个学习曲线很陡峭的过程,通常情况下为了自定义渲染效果往往要和很多文件和设置打交道,这些设置很容易 ...

  9. uni-app中使用scroll-view滚到底部时多次触发scrolltolower事件

    一.前言.scroll-view基本属性: 前言: 前段时间使用scroll-view可滚动视图区域容器来做多个不同内容的展示(在我这个页面中同时使用了三个scroll-view做数据展示),因为这几 ...

  10. Object类和@Data注解

    特别说明:若是有不对的地方欢迎指正 简要概述: Object类是java中所有类默认继承的一个类.下面介绍一下Object类中的一些重要的方法,面试中也是经常会被问到的.尤其是==和equals的区别 ...