博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
codeforces1073D. Berland Fair
阅读量:4136 次
发布时间:2019-05-25

本文共 2755 字,大约阅读时间需要 9 分钟。

D. Berland Fair

time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
XXI Berland Annual Fair is coming really soon! Traditionally fair consists of nn booths, arranged in a circle. The booths are numbered 11 through nn clockwise with nn being 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

inputCopy
3 38
5 2 5
outputCopy
10
inputCopy
5 21
2 4 100 2 6
outputCopy
6
Note
Let’s consider the first example. Here are Polycarp’s moves until he runs out of money:

Booth 11, buys candy for 55, T=33T=33;

Booth 22, buys candy for 22, T=31T=31;
Booth 33, buys candy for 55, T=26T=26;
Booth 11, buys candy for 55, T=21T=21;
Booth 22, buys candy for 22, T=19T=19;
Booth 33, buys candy for 55, T=14T=14;
Booth 11, buys candy for 55, T=9T=9;
Booth 22, buys candy for 22, T=7T=7;
Booth 33, buys candy for 55, T=2T=2;
Booth 11, buys no candy, not enough money;
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 amou

该死的一道题目…一开始全都处理完了,没有想到这是一个循环类型的题,而我只处理了一次,阿西吧.把这个当成一个圈,每次都处理,直到连最便宜的都买不起了就退出,具体解释看代码:

#include
#include
#include
#include
#include
#define ll long longusing namespace std;const int maxx=2e5+10;ll a[maxx];ll n,t;int main(){ while(scanf("%I64d%I64d",&n,&t)!=EOF) { ll ans=0; ll cnt=0; ll sum=0; for(int i=0;i
=a[i]) { t-=a[i]; sum+=a[i]; cnt++; ans++; } } while(sum) { ll count=t/sum; ans+=count*cnt; t-=count*sum; cnt=0; sum=0; for(int i=0;i
=a[i]) { t-=a[i]; sum+=a[i]; cnt++; ans++; } } } printf("%I64d\n",ans); }}

挺值得看的一道题,不难但是不容易做对

努力加油a啊,(o)/~

转载地址:http://xzxvi.baihongyu.com/

你可能感兴趣的文章
Mysql中下划线问题
查看>>
Xcode 11 报错,提示libstdc++.6 缺失,解决方案
查看>>
idea的安装以及简单使用
查看>>
Windows mysql 安装
查看>>
python循环语句与C语言的区别
查看>>
vue 项目中图片选择路径位置static 或 assets区别
查看>>
vue项目打包后无法运行报错空白页面
查看>>
Vue 解决部署到服务器后或者build之后Element UI图标不显示问题(404错误)
查看>>
element-ui全局自定义主题
查看>>
facebook库runtime.js
查看>>
vue2.* 中 使用socket.io
查看>>
openlayers安装引用
查看>>
js报错显示subString/subStr is not a function
查看>>
高德地图js API实现鼠标悬浮于点标记时弹出信息窗体显示详情,点击点标记放大地图操作
查看>>
初始化VUE项目报错
查看>>
vue项目使用安装sass
查看>>
HTTP和HttpServletRequest 要点
查看>>
在osg场景中使用GLSL语言——一个例子
查看>>
laravel 修改api返回默认的异常处理
查看>>
laravel事务
查看>>