AtCoder ABC172 C - Tsundoku 前缀和+二分

注意从a数组的0位置起搜,a数组可以一本书都不读

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<stack>
#include<queue>
using namespace std;
typedef long long ll;

const int maxn = 200090;

ll n,m,k,ans;
ll a[maxn],b[maxn];
ll prea[maxn],preb[maxn];

ll read(){ ll s=0,f=1; char ch=getchar(); while(ch<'0' || ch>'9'){ if(ch=='-') f=-1; ch=getchar(); } while(ch>='0' && ch<='9'){ s=s*10+ch-'0'; ch=getchar(); } return s*f; }

int main(){
    ans=0;
    memset(a,0,sizeof(a));
    memset(b,0,sizeof(b));
    n=read(),m=read(),k=read();
    for(int i=1;i<=n;i++) a[i] = read(),prea[i] = a[i],prea[i] += prea[i-1];
    for(int i=1;i<=m;i++) b[i] = read(),preb[i] = b[i],preb[i] += preb[i-1];
//    for(int i=1;i<=n;i++) printf("%d ",prea[i]); printf("\n"); 
    for(ll i = 0;i <= n; i++ )
     {
        if(prea[i] > k) break;
        ll t = k-prea[i];
        ll pos = upper_bound(preb+1,preb+m+1,t)-preb;
//        printf("%d %d\n",t,pos);
        ans=max(ans,i+pos-1);
    }

    printf("%lld\n",ans);
    
    return 0;
}

 

posted @ 2020-07-30 10:11  Tartarus_li  阅读(388)  评论(0编辑  收藏  举报