HDU 6205 尺取

容易看出来,扩增一倍,找最长的区间就行了

/** @Date    : 2017-09-11 12:43:11
  * @FileName: 1012.cpp
  * @Platform: Windows
  * @Author  : Lweleth (SoungEarlf@gmail.com)
  * @Link    : https://github.com/
  * @Version : $Id$
  */
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <algorithm>
#include <utility>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <stack>
#include <queue>
#include <math.h>
//#include <bits/stdc++.h>
#define LL long long
#define PII pair<int ,int>
#define MP(x, y) make_pair((x),(y))
#define fi first
#define se second
#define PB(x) push_back((x))
#define MMG(x) memset((x), -1,sizeof(x))
#define MMF(x) memset((x),0,sizeof(x))
#define MMI(x) memset((x), INF, sizeof(x))
using namespace std;

const int INF = 0x3f3f3f3f;
const int N = 1e6+20;
const double eps = 1e-8;

int n;
int a[2*N];
int main()
{
	while(~scanf("%d", &n))
	{
		int x, y;
		for(int i = 0; i < n; i++)
			scanf("%d", a + i);
		for(int i = 0; i < n; i++)
			scanf("%d", &y), a[i] = a[i + n] = a[i] - y;
		LL t = 0;
		int l = 0;
		for(int i = 0; i < 2 * n; i++)
		{

			t += a[i];
			//cout <<i <<  t << endl;
			if(i - l + 1 == n) break;
			if(t < 0)
			{
				l = i + 1;
				t = 0;
			}
		}
		printf("%d\n", l);
	}
    return 0;
}
posted @ 2017-09-14 23:24  Lweleth  阅读(173)  评论(0编辑  收藏  举报