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. Shell 格式化输出printf、awk

    目录 Shell 文件的格式化与相关处理 printf.awk 格式化打印printf 案例.格式化输出文件内容 输出命令echo 案例 awk数据处理工具 语法格式 处理流程 AWK内置变量 条件 ...

  2. applogs流量数据项目学习

    一. 项目介绍 项目的功能主要是面向App开发商提供App使用情况的统计服务 主要是基于用户启动app的统计分析,app只要启动就会上报一条日志记录 (启动日志),当然也会有其他的日志比如说页面访问日 ...

  3. css系列,选择器权重计算方式

    CSS选择器分基本选择器(元素选择器,类选择器,通配符选择器,ID选择器,关系选择器), 属性选择器,伪类选择器,伪元素选择器,以及一些特殊选择器,如has,not等. 在CSS中,权重决定了哪些CS ...

  4. [php代码审计] 通读审计之shangfancms

    前言 大部分的MVC框架,访问的控制器大部分是由外部参数来决定的,那么本篇文章所通读的MVC框架与之前的一系列MVC框架不太一样,它的路由是由程序本身的路由表来决定的. 源码下载 https://ww ...

  5. 最长公共子序列问题(LCS) 洛谷 P1439

    题目:P1439 [模板]最长公共子序列 - 洛谷 | 计算机科学教育新生态 (luogu.com.cn) 关于LCS问题,可以通过离散化转换为LIS问题,于是就可以使用STL二分的方法O(nlogn ...

  6. STM32一些特殊引脚做IO使用的注意事项

    1 PC13.PC14.PC15的使用 这三个引脚与RTC复用,<STM32参考手册>中这样描述: PC13 PC14 PC15需要将VBAT与VDD连接,实测采用以下程序驱动4个74HC ...

  7. Linux FTP的主动模式与被动模式

    Linux FTP的主动模式与被动模式 一.FTP主被动模式        FTP是文件传输协议的简称,ftp传输协议有着众多的优点所以传输文件时使用ftp协议的软件很多,ftp协议使用的端口是21( ...

  8. Linux基础命令---vmstat显示虚拟内存状态

    vmstat vmstat指令用来显示虚拟内存使用状态,同时也可以显示进程.cpu活动情况.vmstat报告有关进程.内存.分页.块IO.陷阱和CPU活动的信息.生成的第一份报告给出了自上次重新启动以 ...

  9. vue-cli 如何配置assetsPublicPath; vue.config.js如何更改assetsPublicPath配置;

    问题: vue项目完成打包上线的时候遇到静态资源找不到的问题,网上很多解决办法都是基于vue-cli 2.x 来解决的,但从vue-cli 3.0以后,便舍弃了配置文件夹(便没有了config这个文件 ...

  10. Function Overloading in C++

    In C++, following function declarations cannot be overloaded. (1)Function declarations that differ o ...