time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

XXI Berland Annual Fair is coming really soon! Traditionally fair consists of nnn booths, arranged in a circle. The booths are numbered 111through nnn clockwise with nnn being adjacent to 111. The iii-th booths sells some candies for the price of aia_iai​i burles per item. Each booth has an unlimited supply of candies.

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

  • at first, he visits booth number 111;
  • 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 nnn and T(1≤n≤2⋅105,1≤T≤1018)T (1≤n≤2⋅10^5, 1≤T≤10^{18})T(1≤n≤2⋅105,1≤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,…,an(1≤ai≤109)a_1,a_2,…,a_n (1≤a_i≤10^9)a1​,a2​,…,an​(1≤ai​≤109) — the price of the single candy at booth number iii.

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 111, buys candy for 555, T=33T=33T=33;
  2. Booth 222, buys candy for 222, T=31T=31T=31;
  3. Booth 333, buys candy for 555, T=26T=26T=26;
  4. Booth 111, buys candy for 555, T=21T=21T=21;
  5. Booth 222, buys candy for 222, T=19T=19T=19;
  6. Booth 333, buys candy for 555, T=14T=14T=14;
  7. Booth 111, buys candy for 555, T=9T=9T=9;
  8. Booth 222, buys candy for 222, T=7T=7T=7;
  9. Booth 333, buys candy for 555, T=2T=2T=2;
  10. Booth 111, buys no candy, not enough money;
  11. Booth 222, buys candy for 222, T=0T=0T=0.

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

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

题意

nnn种糖果围成一圈,每种糖果每个aia_iai​元。初始时你有TTT元,接着你从111开始绕圈。一旦你发现有糖果能买,你就买一个。直到一个糖果都买不起。问最后买了多少个糖果。

Slove

首先对数据进行处理:nnn种糖果全部买一次需要多少钱,找到nnn种糖果中最便宜的价格

然后计算所有的糖果均能买的圈数有多少。

将剩余的钱进行进行按圈数模拟:一圈一圈的模拟肯定是不行的,稳稳地超时,所以需要进行优化

将剩余的钱数与当前所在位置的糖果价格进行比较,更新钱数,并记录每一圈结束后的次大值,当次大值等于最小值的时候,证明已经不能买除了最便宜的糖果外的其他糖果,此时结束循环。将剩余的钱数除以最小值(向下取整)可得到最终剩余的钱能买糖果数

Code

代码用时:77ms

/*************************************************************************
> File Name: D.cpp
> Author: WZY
> Created Time: 2019年02月15日 16:33:54
************************************************************************/ #include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define ms(a,b) memset(a,b,sizeof(a))
#define pi acos(-1.0)
#define INF 0x7f7f7f7f
#define debug(...) cerr<<"["<<#__VA_ARGS__":"<<(__VA_ARGS__)<<"]"<<"\n"
const double E=exp(1);
const int maxn=1e6+10;
const int mod=1e9+7;
using namespace std;
ll a[maxn];
ll sum[maxn];
int main(int argc, char const *argv[])
{
ios::sync_with_stdio(false);
cin.tie(0);
int n;
ll t;
cin>>n>>t;
ll minn=1e18+10;
ll sum=0;
for(int i=1;i<=n;i++)
{
cin>>a[i];
sum+=a[i];
minn=min(minn,a[i]);
}
ll ans=0;
ll res=t/sum;
ans+=res*n;
ll s=t%sum;
if(s==0)
{
cout<<ans<<endl;
return 0;
}
ll minnn=1e9+10;
while(s>minn)
{
ll _=minnn;
for(int i=1;i<=n;i++)
{
if(s>=a[i])
{
s-=a[i];
ans++;
// 更新次小值
if(a[i]!=minn&&a[i]<minnn&&a[i]!=minn)
minnn=a[i];
}
}
// 如果次小值没有得到更新,并且次小值大于剩余钱数,证明只有最小钱数的糖果可以购买
if(minnn==_&&s<minnn)
break;
}
ans+=s/minn;
cout<<ans<<endl;
return 0;
}

Codeforces 1073D:Berland Fair(模拟)的更多相关文章

  1. CodeForces - 1073D Berland Fair

    XXI Berland Annual Fair is coming really soon! Traditionally fair consists of nnbooths, arranged in ...

  2. codeforces 897A Scarborough Fair 暴力签到

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

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

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

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

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

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

  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. 【CF1073D】Berland Fair(模拟)

    题意:初始有t元,每次从1开始买,从1到n依次有n个人,每个人的东西价格为a[i],该人依次能买就买,到n之后再回到1从头开始,问最后能买到的东西数量 n<=2e5,t<=1e18,a[i ...

随机推荐

  1. SpringBoot整合Shiro 四:认证+授权

    搭建环境见: SpringBoot整合Shiro 一:搭建环境 shiro配置类见: SpringBoot整合Shiro 二:Shiro配置类 shiro整合Mybatis见:SpringBoot整合 ...

  2. Flume(四)【配置文件总结】

    目录 一.Agent 二.Source taildir arvo netstat exec spooldir 三.Sink hdfs kafka(待续) hbase(待续) arvo logger 本 ...

  3. nodeJs-Stream接口

    JavaScript 标准参考教程(alpha) 草稿二:Node.js Stream接口 GitHub TOP Stream接口 来自<JavaScript 标准参考教程(alpha)> ...

  4. Android Menu的基本用法

    使用xml定义Menu 菜单资源文件必须放在res/menu目录中.菜单资源文件必须使用<menu>标签作为根节点.除了<menu>标签外,还有另外两个标签用于设置菜单项和分组 ...

  5. Xcode功能快捷键

    隐藏xcode command+h退出xcode command+q关闭窗口 command+w关闭所有窗口 command+option+w关闭当前项目 command+control+w关闭当前文 ...

  6. Linux基础命令---lftp登录ftp服务器

    lftp lftp指令可以用来登录远程ftp服务器,这是一个字符界面的文件传输工具. 此命令的适用范围:RedHat.RHEL.Ubuntu.CentOS.SUSE.openSUSE.Fedora. ...

  7. zabbix之主动模式和proxy的主动模式

    #:找一台新主机配置上agent,注意版本要和server端保持一样 #:官网地址:https://www.zabbix.com/documentation/4.0/zh/manual/install ...

  8. vue2 页面路由

    vue官方文档 src/views/Login.vue <template> <div> <h2>登录页</h2> </div> </ ...

  9. 【Linux】【Basis】磁盘分区

    1. Linux磁盘及文件系统管理 1.1. 基本概念: 1.1.1. 磁盘接口类型: IDE(ata):并口,133MB/s,设备/dev/hd[a-z] SCSI:并口,Ultrascsi320, ...

  10. 使用Booststrap布局网页页面

    <!DOCTYPE html><html lang="zh-CN"><head> <meta charset="utf-8&qu ...