ural 1998 The old Padawan

先预处理每一个点往前退几步

就一个trick。。要处理这一秒已经超出了要拿完所花的时间


 

#include <iostream>
#include <cstring>
#include <string>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#define inf 0x3f3f3f3f
typedef __int64 ll;
using namespace std;

int c[100005],w[100005],s[100005],t[100005],tmp,N,n,m,k,i,cnt,pos,ans;

int main()
{
    while(~scanf("%d%d%d",&n,&m,&k))
    {
        for(i=1;i<=n;i++)
            scanf("%d",&w[i]);
        for(i=1;i<=m;i++)
            scanf("%d",&t[i]);
        s[n]=w[n];
        tmp=n-1;
        cnt=1;
        while(s[n]<=k&&tmp>0)
        {
            s[n]+=w[tmp];
            tmp--;
            cnt++;
        }
        c[n]=cnt;
        N=n-1;
        while(N)
        {
            s[N]=s[N+1]-w[N+1];
            cnt--;
            while(s[N]<=k&&tmp>0)
            {
                s[N]+=w[tmp];
                tmp--;
                cnt++;
            }
            c[N]=cnt;
           // printf("N:%d cnt:%d tmp:%d\n",N,cnt,tmp);
            if(tmp<=0)
            {
                for(i=N;i>0;i--)
                {
                    c[i]=i;
                }
                break;
            }
            N--;
        }
        //处理每一个分散注意力的秒
        sort(t+1,t+m+1);
        t[0]=0;
        ans=0;
        pos=0;
        for(i=1;i<=m;i++)
        {
            tmp=(t[i]-t[i-1]);
            pos+=tmp;
            if(pos>n){//时间超出了全部拿完的时间
                pos-=tmp;
                break;
            }
            ans+=tmp;
            pos=pos-1-c[pos-1];

        }
        ans+=(n-pos);
        printf("%d\n",ans);
    }
    return 0;
}


 

 

posted on 2013-10-29 21:39  新一  阅读(167)  评论(0)    收藏  举报

导航