Kabaleo Lite
用带负数的大整数用__int128
#include <bits/stdc++.h> #define ll long long using namespace std; const int MAXN=200050,INF=0x3fffffff; ll n,a[MAXN],b[MAXN],minb[MAXN]; __int128 ans,sum[MAXN],maxs[MAXN]; inline void output () { long long y[120] , i; i = 0; if ( ans < 0 ) { printf ( "-" ); ans = -ans; } while ( ans ) { y[++i] = ans % 10; ans = ans / 10; } for ( i ; i >= 1 ; i-- ) printf ( "%lld" , y[i] ); } inline void solve(int cs){ ans=0; memset(sum,0,sizeof sum); scanf("%lld",&n); scanf("%lld",a+1); sum[1]=a[1]; maxs[1]=sum[1]; for(ll i=2;i<=n;i++){ scanf("%lld",a+i); sum[i]=sum[i-1]+a[i]; maxs[i]=max(maxs[i-1],sum[i]); } scanf("%lld",b+1); minb[1]=b[1]; for(ll i=2;i<=n;i++){ scanf("%lld",b+i); minb[i]=min(minb[i-1],b[i]); } for(ll i=1;i<n;i++){ minb[i]=minb[i]-minb[i+1]; if(maxs[i]>=a[1]) ans+=minb[i]*maxs[i]; } ans+=minb[n]*maxs[n]; printf("Case #%d: %lld ",cs,b[1]); output(); printf("\n"); } int main(){ int T; scanf("%d",&T); for(int t=1;t<=T;t++){ solve(t); } // while(1){ // solve(); // } return 0; }