1 条题解

  • 0
    @ 2026-4-27 1:08:15
    #include<bits/stdc++.h>
    using namespace std;
    const int MAXN=3e5+5;
    int n,a[MAXN],b[MAXN],s[MAXN];
    signed main() {
    	scanf("%d",&n);
    	for(int i=1;i<=n;++i) scanf("%d",&a[i]);
    	for(int i=1;i<=n;++i) scanf("%d",&b[i]);
    	int w=0;
    	for(int i=1,j=0;i<=n;++i) {
    		while(b[i]&&j) {
    			int x=min(b[i],a[s[j]]);
    			w+=x,b[i]-=x,a[s[j]]-=x;
    			if(!a[s[j]]) --j;
    		}
    		s[++j]=i;
    	}
    	for(int i=1;i<=n;++i) w-=max(0,b[i]-a[i]);
    	printf("%d\n",w);
    	return 0;
    }
    
    
    • 1

    信息

    ID
    10945
    时间
    1000ms
    内存
    1024MiB
    难度
    10
    标签
    递交数
    1
    已通过
    1
    上传者