AcWing 499. 聪明的质监员
生活随笔
收集整理的這篇文章主要介紹了
AcWing 499. 聪明的质监员
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
解題思路:
https://www.acwing.com/solution/content/33961/
代碼如下:
#include <iostream> using namespace std; const int N = 200010; int w[N],v[N],L[N],R[N]; typedef long long LL; LL cnt[N],b[N]; int n,m; LL S; LL get_Y(int mid) {for (int i = 1;i<=n;i++){if (w[i] >= mid){b[i] = b[i-1]+v[i];cnt[i] = cnt[i-1]+1;}else{b[i] = b[i-1];cnt[i] = cnt[i-1];}}LL res = 0;for (int i = 0;i<m;i++){res+=(b[R[i]]-b[L[i]-1])*(cnt[R[i]]-cnt[L[i]-1]);}return res; }int main() {cin>>n>>m>>S;for (int i = 1;i<=n;i++) cin>>w[i]>>v[i];for (int i = 0;i<m;i++) cin>>L[i]>>R[i];int l = 0,r = 1e6+1;while(l < r){int mid = l+r+1>>1;if (get_Y(mid)>=S) l = mid;else r = mid-1;}cout<<min(abs(S-get_Y(r)),abs(S-get_Y(r+1)))<<endl;return 0; } 創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎總結
以上是生活随笔為你收集整理的AcWing 499. 聪明的质监员的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: steam错误并提示无法连接至steam
- 下一篇: 二分边界