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 ;
}

card card card HDU - 6205的更多相关文章

  1. 【BZOJ4391】[Usaco2015 dec]High Card Low Card(贪心)

    [BZOJ4391][Usaco2015 dec]High Card Low Card(贪心) 题面 BZOJ 题解 预处理前缀后缀的结果,中间找个地方合并就好了. #include<iostr ...

  2. 【题解】P3129高低卡(白金)High Card Low Card

    [题解][P3129 USACO15DEC]高低卡(白金)High Card Low Card (Platinum) 考虑贪心. 枚举在第几局改变规则,在改变规则之前,尽量出比它大的最小的牌,在改变规 ...

  3. hdu 6205 card card card 尺取法

    card card card Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)To ...

  4. 2017ICPC沈阳网络赛 HDU 6205 -- card card card(最大子段和)

    card card card Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)To ...

  5. hdu 6205 card card card

    https://vjudge.net/contest/184514#problem/L题意:排成一行的一堆牌,每堆牌都有一定数量的牌,然后每堆牌对应有一个惩罚值.一开始所有的牌都是正面向下的,并且在游 ...

  6. HDU 6205 (模拟) card card card

    题目链接 Problem Description As a fan of Doudizhu, WYJ likes collecting playing cards very much. One day ...

  7. hdu 6205 card card card 最大子段和

    #include<iostream> #include<deque> #include<memory.h> #include<stdio.h> #inc ...

  8. HDU 6205 card card card ( 思维 )

    题意 : 给定两个序列 a 和 b ,保证 a 数列的和 == b数列的和,从头到尾考虑 (a[i] - b[i]) 的前缀和,直到前缀和为负数则无法进行下去,所得的便是a[1~i]的和,现在有一个操 ...

  9. hdu 6205: card card card【输入挂】

    题目链接 感谢 http://blog.csdn.net/txgang/article/details/77568491 以下供参考 getchar读入法 2683MS FastIO法 MX=1e2 ...

随机推荐

  1. 【自适应辛普森积分】hdu1724 Ellipse

    Ellipse Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Sub ...

  2. JavaScript语言学习中的注意事项

    javascript: 基于浏览器 基于对象 事件驱动 脚本语言 由: javascript: ECMAscript(ES) DOM文档对象模型 BOM浏览器对象模型,三部分组成 使用js的三种方式 ...

  3. SDN第三次作业

    作业链接 阅读文章:http://www.sdnlab.com/19777.html 阅读<重构网络>第一二章 列举openflow1.0的12元组? 入端口 源MAC地址 目的MAC地址 ...

  4. 使用VS Code开发asp.net core (上)

    本文是基于Windows10的. 下载地址: https://code.visualstudio.com/ insider 版下载地址: https://code.visualstudio.com/i ...

  5. a元素的两个重要功能和表格布局

    ⦁ 发送邮件:<a href="mailto:231455557@qq.com">联系我们</a> ⦁ 锚点两个重要应用:查看目录    提供菜单功能回到顶 ...

  6. 017 Java中的静态代理、JDK动态代理、cglib动态代理

    一.静态代理 代理模式是常用设计模式的一种,我们在软件设计时常用的代理一般是指静态代理,也就是在代码中显式指定的代理. 静态代理由业务实现类.业务代理类两部分组成.业务实现类负责实现主要的业务方法,业 ...

  7. 使用EL表达式调用java方法

    首先,新建一个类,类中写一个静态方法 public class PrivilegeUtils { public static Boolean checkPrivilegeByName(User use ...

  8. 教我徒弟Android开发入门(二)

    前言: 上一期实现了简单的QQ登录效果,这一期继续对上一期进行扩展 本期的知识点: Toast弹窗,三种方法实现按钮的点击事件监听 正文:   Toast弹窗其实很简单,在Android Studio ...

  9. WinForm中使用DDE技术(含源码)

    提起DDE技术,相信很多人不知道是啥东东,尤其是90后的程序员们.不过,有时候这个东西还是有用处的,用一句话可以总结:实现Winform程序间的通信.比如:两个Winform程序A和B需要实现通信,用 ...

  10. npm注意事项(附带Vue-cli安装)

    下载完nodeJS后,可选择更改配置目录 1.npm config set prefix "D:\node\node-global"<!--配置全局安装目录--> 2. ...