card card card

Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 450    Accepted Submission(s): 195

Problem Description

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 n 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 penaltyvalue.
If at one moment, the number of cards he holds which are face-up is less than the penaltyvalue, 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.
 

Input

There are about 10 test cases ending up with EOF.
For each test case:
the first line is an integer n (1≤n≤106), denoting n heaps of cards;
next line contains n integers, the ith integer ai (0≤ai≤1000) denoting there are ai cards in ith heap;
then the third line also contains n integers, the ith integer bi (1≤bi≤1000) denoting the "penalty value" of ith heap is bi.
 

Output

For 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]

 

Source

 
 //2017-09-10
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std; const int N = ;
int A[N], B[N], n; int main()
{
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 ans = , sum1 = , sum2 = , ptr1, ptr2;
for(ptr1 = ; ptr1 < n; ptr1++){
sum1 += A[ptr1]-B[ptr1];
if(sum1 < )break;
}
for(ptr2 = n-; ptr2 >= ptr1; ptr2--){
sum2 += A[ptr2]-B[ptr2];
if(sum2 >= ){
ans = ptr2;
sum2 = ;
}
}
printf("%d\n", ans);
} return ;
}

HDU6205的更多相关文章

  1. HDU6205 Coprime Sequence 2017-05-07 18:56 36人阅读 评论(0) 收藏

    Coprime Sequence                                                        Time Limit: 2000/1000 MS (Ja ...

随机推荐

  1. 数组-Array

    1.数组的概念 /* 数组的格式 数组: 同一种数据类型的若干个值的容器 元素:数组中的值称为元素 索引:元素的标号,从0开始 长度:数组中元素的个数 */ public class ArrayDem ...

  2. zookeeper学习day01

    1.zkAPI:(借助闭锁来实现)    1)创建闭锁对象  2)创建zk对象  3)连接zk客户端(连接成功执行countDown方法)  4)执行await方法(保证链接成功) 5)zk对象调用对 ...

  3. .Wait()与.GetAwaiter()之间有什么区别

    两者都是同步等待操作的结果差异主要在于处理异常.使用Wait,异常堆栈跟踪不会改变并表示异常时的实际堆栈,因此如果您有一段代码在线程池线程上运行,那么您将拥有类似的堆栈 ThreadPoolThrea ...

  4. Learning WCF:Fault Handling

    There are two types of Execptions which can be throwed from the WCF service. They are Application ex ...

  5. 如果你在it院校学习累了,你能干什么?

    文章来源i春秋,未经允许不得转载    工具链接https://bbs.ichunqiu.com/portal.php 如果你在国内的it院校累了,有些厌倦了,你该怎么办?    分享一些joke以前 ...

  6. Android 使用 HTTPS 问题解决(SSLHandshakeException)

    title date categories tags Android 5.0以下TLS1.x SSLHandshakeException 2016-11-30 12:17:02 -0800 Andro ...

  7. Shell-3--变量

    用户自定义变量 环境变量 位置参数变量 预定义变量

  8. Spring Boot 单元测试详解+实战教程

    Spring Boot 的测试类库 Spring Boot 提供了许多实用工具和注解来帮助测试应用程序,主要包括以下两个模块. spring-boot-test:支持测试的核心内容. spring-b ...

  9. Win10手记-为应用集成SQLite(一)

    SQLite是什么?熟悉移动端开发的朋友都会经常接触,无论是iOS的CoreData还是安卓的内置数据库,他们都是采用了SQLite这个轻量高效数据库,微信也是如此.可以说SQLite是目前移动端最为 ...

  10. tomcat容器是如何创建servlet类实例?用到了什么原理?

    当容器启动时,会读取在webapps目录下所有的web应用中的web.xml文件,然后对 xml文件进行解析,并读取servlet注册信息.然后,将每个应用中注册的servlet类都进行加载,并通过  ...