编程介的小学生 2017-12-05 07:04 采纳率: 20.5%
浏览 854
已采纳

Chain

Problem Description
Li Lei has many pearls of N different color. The number of each color is limited. Han Mei is Li Lei’s girl friend.
Since Han Mei’s birthday is coming, Li Lei wants to give Han Mei his present for her birthday. Finally, Li Lei decides to make a chain for his lovely girl friend with his beautiful pearls. He wants to make the chain more beautiful, so the number of the continuous pearls with same color is limited.
Now, Li Lei wants to know how long his chain will be. He will always make the chain as long as possible. Pay attention that the shape of a chain is a line but not a circle here.

Input
The first line is an integer N. It means that Li Lei has many pearls of N different color.
The next line contains N integers A(0),A(1)……A(N-1). It means that Li Lei has A(i) pearls of the i-th color.
The third line contains N integers B(0),B(1)……B(N-1). It means that in the chain, there will be no more than B(i) continuous pearls of the i-th color.
You can assume that A(i) is not smaller than B(i).
All integers in the input is positive and no larger than 100000.

Output
There is one integer in a line for each test case, representing the length of the chain.

Sample Input
3
1 1 100
1 1 1
3
1 1 100
1 1 2

Sample Output
5
8

  • 写回答

1条回答 默认 最新

报告相同问题?

悬赏问题

  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥20 为什么我写出来的绘图程序是这样的,有没有lao哥改一下
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥200 关于#c++#的问题,请各位专家解答!网站的邀请码
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号