我很蒟蒻 60分代码 #include <bits/stdc++.h> typedef long long int LL; using namespace std; const int N=1e6+10; LL n,income[N],rate[N],T;
struct DATA { LL rate=0,money=0; DATA(){}; DATA(LL r,LL m):rate(r),money(m){}; }q[N];
bool work(LL MID) { LL nowm=0,nowc=0,havecost=0; LL L=1,R=0; for(LL i=1;i<=n;i++) { nowm+=income[i]; while(L<=R&&q[R].rate<=rate[i]) R—; q[++R]=DATA(rate[i],nowm); if(nowc<MID) { while(nowc<MID&&L<=R) { LL Lrate=q[L].rate,Lm=q[L].money-havecost; LL need=MID-nowc; LL getm=min((need+Lrate-1)/Lrate,Lm); nowc+=getm*Lrate; havecost+=getm; Lm-=getm; if(Lm==0) L++; else break; } if(nowc<MID) return false; } nowc-=MID; } return true; }
int main() { scanf(“%lld”,&T); while(T—) { LL L=0,R=0,maxr=0; memset(rate,0,sizeof(rate)); memset(income,0,sizeof(income)); cin>>n; for(LL i=1;i<=n;i++) scanf(“%lld”,&rate[i]),maxr=max(maxr,rate[i]); for(LL i=1;i<=n;i++) scanf(“%lld”,&income[i]),R+=maxr*income[i]; R/=n; L=0; while(L<=R) { LL MID=(L+R)>>1; if(!work(MID)) {
-
-
} printf(“%lld\n”,R); } return 0; }代码 R=MID-1; } else { L=MID+1; }
-