3个对,没有超时,不用二分

P1843 奶牛晒衣服

```cpp #include<bits/stdc++.h> //#pragma GCC optimize(2)//O2优化 using namespace std; typedef long long ll; typedef long double ld; const int N=500000+10; ll n,a,b,x; ll ans,ant,num; priority_queue<int> q; ll read() { ll res=0,chr=getchar(),st=1; if(chr=='-') { st=-1; } while(!isdigit(chr)&&chr!=EOF) { chr=getchar(); } while(isdigit(chr)) { res=(res*10)+(chr-'0'); chr=getchar(); } return res*st; } int main() { n=read(); a=read(); b=read(); for(int i=1;i<=n;i++) { x=read(); q.push(x); } while(1) { ant+=a; num++; ans=q.top(); ans-=b; if(ans<=ant) { cout<<num; return 0; } q.pop(); q.push(ans); } return 0; } ```
by dfydada⚡⚡⚡ @ 2019-08-13 20:44:06


|