80 Days-尺取法模板题

  • http://hihocoder.com/problemset/problem/1831
  • #include <bits/stdc++.h>
    using namespace std;
    const int N=1000005;
    int p[N<<1],a[N],b[N];
    int main()
    {
        int T,n,c;
        scanf("%d",&T);
        while(T--)
        {
            scanf("%d%d",&n,&c);
            for(int i=1; i<=n; i++)
                scanf("%d",&a[i]);
            for(int i=1; i<=n; i++)
            {
                scanf("%d",&b[i]);
                p[i]=p[i+n]=a[i]-b[i];
            }
            int l=1,r=1;
            long long num=c;
            while(l<=n&&r-l+1<=n)
            {
                num+=p[r++];
                while(num<0)
                    num-=p[l++];
            }
            printf("%d\n",l>n?-1:l);
        }
        return 0;
    }
  •  

猜你喜欢

转载自blog.csdn.net/BePosit/article/details/82822910
80