As a fan of Doudizhu, WYJ likes collecting playing cards very much. 
One day, MJF takes a stack of cards and talks to him: let's play a game and if you win, you can get all these cards. MJF randomly assigns these cards into nn heaps, arranges in a row, and sets a value on each heap, which is called "penalty value". 
Before the game starts, WYJ can move the foremost heap to the end any times. 
After that, WYJ takes the heap of cards one by one, each time he needs to move all cards of the current heap to his hands and face them up, then he turns over some cards and the number of cards he turned is equal to the penaltyvaluepenaltyvalue. 
If at one moment, the number of cards he holds which are face-up is less than the penaltyvaluepenaltyvalue, then the game ends. And WYJ can get all the cards in his hands (both face-up and face-down). 
Your task is to help WYJ maximize the number of cards he can get in the end.So he needs to decide how many heaps that he should move to the end before the game starts. Can you help him find the answer? 
MJF also guarantees that the sum of all "penalty value" is exactly equal to the number of all cards. 

InputThere are about 1010 test cases ending up with EOF. 
For each test case: 
the first line is an integer nn (1≤n≤1061≤n≤106), denoting nn heaps of cards; 
next line contains nn integers, the iithth integer aiai (0≤ai≤10000≤ai≤1000) denoting there areaiai cards in iithth heap; 
then the third line also contains nn integers, the iithth integer bibi (1≤bi≤10001≤bi≤1000) denoting the "penalty value" of iithth heap is bibi. 
OutputFor each test case, print only an integer, denoting the number of piles WYJ needs to move before the game starts. If there are multiple solutions, print the smallest one. 
Sample Input

5
4 6 2 8 4
1 5 7 9 2

Sample Output

4

Hint

[pre]
For the sample input: + If WYJ doesn't move the cards pile, when the game starts the state of cards is:
4 6 2 8 4
1 5 7 9 2
WYJ can take the first three piles of cards, and during the process, the number of face-up cards is 4-1+6-5+2-7. Then he can't pay the the "penalty value" of the third pile, the game ends. WYJ will get 12 cards.
+ If WYJ move the first four piles of cards to the end, when the game starts the state of cards is:
4 4 6 2 8
2 1 5 7 9
WYJ can take all the five piles of cards, and during the process, the number of face-up cards is 4-2+4-1+6-5+2-7+8-9. Then he takes all cards, the game ends. WYJ will get 24 cards. It can be improved that the answer is 4. **huge input, please use fastIO.**
[/pre] 给你两个数组,数组的元素和相等 让你将a[i]-b[i]的值的和最大
其实只要找到最后一段(a[i]-b[i])和小于0的点就行了 下面上代码
 #include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
int a[],b[];
int main() {
int n;
while(scanf("%d",&n)!=EOF){
for (int i= ;i<n ;i++ )
scanf("%d",&a[i]);
for (int i= ;i<n ;i++)
scanf("%d",&b[i]);
int sum=,ans=;
for (int i= ;i<n ;i++ ){
sum+=(a[i]-b[i]);
if (sum<) {
ans=i+;
sum=;
}
}
printf("%d\n",ans);
}
return ;
}

最新文章

  1. HashMap源码阅读笔记(基于jdk1.8)
  2. 转载:Android自动化测试- 自动获取短信验证码
  3. VUE 入门基础(1)
  4. Python 3 利用 subprocess 实现管道( pipe )交互操作读/写通信
  5. nyoj998(euler)
  6. Python核心编程--学习笔记--3--Python基础
  7. Spring学习总结二——SpringIOC容器二
  8. OpenSSL 拒绝服务漏洞
  9. win8下光驱消失
  10. Linode VPS上架日本东京2号机房,性能速度评测报告(推荐)
  11. 理解angularJs中的$on,$broadcast,$emit
  12. ABP .Net Core 日志组件集成使用NLog
  13. static关键字特点
  14. 带着新人学springboot的应用11(springboot+Dubbo+Zookeeper 上)
  15. nginx php-fpm开启session
  16. Eclipse 中构建 Maven 项目的完整过程 - SpringBoot 项目
  17. 用递归方法计算斐波那契数列(Recursion Fibonacci Sequence Python)
  18. win7安装vs2017时闪退
  19. std::string 字符串替换
  20. 结巴分词和自然语言处理HanLP处理手记

热门文章

  1. 给你的jQuery项目赋予Router技能吧
  2. SqlServer循环 和 批量倒数据
  3. dos命令(入门)
  4. PLECS—晶闸管-第九周
  5. php常用面试知识点
  6. Nginx限流办法
  7. Tesseract OCR win 32位编译
  8. javascript高级程序设计第三章的一些笔记
  9. hihoCoder 1051 : 补提交卡 枚举
  10. 编写React组件的最佳实践