跳到正文

题解

题解:P12000 扶苏出勤日记

用户 1674785约 2 分钟
原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2025年12月12日
篇幅
约 2 分钟
题目
P12000

版本

  1. v2当前
  2. v1

我很蒟蒻 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)) {

    1. 代码
        		R=MID-1;
        }
        else
        {
        	L=MID+1;
        }
      
      } printf(“%lld\n”,R); } return 0; }
原文