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. 我可以减肥失败,但我的 Docker 镜像一定要瘦身成功!

    作者|徐伟 来源|尔达 Erda 公众号 ​ 简介 容器镜像类似于虚拟机镜像,封装了程序的运行环境,保证了运行环境的一致性,使得我们可以一次创建任意场景部署运行.镜像构建的方式有两种,一种是通过 do ...

  2. volatile原理和应用场景

    volatile是java语言中的一个关键字,常用于并发编程,有两个重要的特点:具有可见性,java虚拟机实现会为其满足Happens before原则;不具备原子性.用法是修饰变量,如:volati ...

  3. Java、Scala获取Class实例

    Java获取Class实例的四种方式 package com.test; /** * @description: TODO * @author: HaoWu * @create: 2020/7/22 ...

  4. js正则表达式之密码强度验证

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  5. GPU随机采样速度比较

    技术背景 随机采样问题,不仅仅只是一个统计学/离散数学上的概念,其实在工业领域也都有非常重要的应用价值/潜在应用价值,具体应用场景我们这里就不做赘述.本文重点在于在不同平台上的采样速率,至于另外一个重 ...

  6. CSS基础语法(一)

    目录 CSS基础语法(一) 一.CSS简介 1.CSS语法规范 2.CSS代码风格 二.CSS基础选择器 1.标签选择器 2.类选择器 3.id选择器 4.通配符选择器 5.总结 三.CSS字体属性 ...

  7. APK 反编译以及遇到的问题

    APK反编译: https://www.cnblogs.com/geeksongs/p/10864200.html 遇到的问题 https://www.jianshu.com/p/55bf5f688e ...

  8. RestTemplate的exchange()方法,解决put和delete请求拿不到返回值的问题

    嗷嗷待哺的controller(被调用provider的controller方法) //测试get少量参数 @RequestMapping(value = "detailsGetD" ...

  9. Linux学习 - ACL权限

    一.ACL权限简介 ACL权限是为了防止权限不够用的情况,一般的权限有所有者.所属组.其他人这三种,当这三种满足不了我们的需求的时候就可以使用ACL权限 二.ACL权限开启 1 查看当前系统分区 df ...

  10. 【Linux】【Shell】【Basic】条件测试和变量

    bash脚本编程       脚本文件格式:         第一行,顶格:#!/bin/bash         注释信息:#         代码注释:         缩进,适度添加空白行:   ...