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. Spring整合Mybatis报 java.lang.ClassNotFoundException:org.springframework.core.metrics.ApplicationStartup,即:spring的版本过高,采用RELEASE稳定版

    1.遇到的问题: 今天在弄spring整合mybatis的时候遇到一个小问题,如图所示: 简单来说:就是我的spring的xml文件没找到,我就奇了怪了,我所有的配置都没问题啊! 我pom.xml配置 ...

  2. Hadoop入门 概念

    Hadoop是分布式系统基础架构,通常指Hadoop生态圈 主要解决 1.海量数据的存储 2.海量数据的分析计算 优势 高可靠性:Hadoop底层维护多个数据副本,即使Hadoop某个计算元素或存储出 ...

  3. 日常Java 2021/11/2

    Java提供了一种对象序列化的机制,该机制中,一个对象可以被表示为一个字节序列,该字节序列包括该对象的数据.有关对象的类型的信息和存储在对象中数据的类型.将序列化对象写入文件之后,可以从文件中读取出来 ...

  4. 日常Java 2021/10/17

    今天开始Javaweb编译环境调试,从tomcat容器开始,然后mysql的下载,连接工具datagrip,navicat for mysql,然后就是编写自己的sql,安装jdbc,eclipse连 ...

  5. 手淘lib-flexible布局适配方案

    前置知识:什么是rem CSS3新增的一个相对单位rem(root em,根em).rem是相对于根节点(或者是html节点).如果根节点设置了font-size:10px;那么font-size:1 ...

  6. Linux基础命令---ntpdate网络时间服务器

    ntpdate ntpdate指令通过轮询指定为服务器参数的网络时间协议(NTP)服务器来设置本地日期和时间,从而确定正确的时间. 此命令的适用范围:RedHat.RHEL.Ubuntu.CentOS ...

  7. zabbix之二进制安装

    #:参考官方网站 https://www.zabbix.com/documentation/4.0/manual/installation/install_from_packages/debian_u ...

  8. swagger文档

    关键配置文件 spring boot demo pom.xml <?xml version="1.0" encoding="UTF-8"?> < ...

  9. java使用在线api实例

    字符串 strUrl为访问地址和参数 public String loadAddrsApi() { StringBuffer sb; String strUrl = "https://api ...

  10. Grafana 任意文件读取漏洞 (CVE-2021-43798)学习

    漏洞概述 Grafana是一个跨平台.开源的数据可视化网络应用程序平台.用户配置连接的数据源之后,Grafana可以在网络浏览器里显示数据图表和警告. Grafana 的读取文件接口存在未授权,且未对 ...