zoukankan      html  css  js  c++  java
  • 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;
    }
  • 相关阅读:
    Codeforces-541div2
    动态规划-线性dp-hdu-4055
    动态规划_线性dp
    动态规划_背包问题笔记
    codeforces-1111
    数论模板
    codeforces-1114F-线段树练习
    2-sat
    拓扑排序
    强连通分量
  • 原文地址:https://www.cnblogs.com/tuchen/p/13402209.html
Copyright © 2011-2022 走看看