- 砍树
为啥八十分
- 2024-4-9 20:51:19 @
#include<bits/stdc++.h> using namespace std; #define ll long long ll n,m; ll a[1000010]; bool check(int x) { int res=0; for(int i=0;i<n;i++) { if(a[i]>x) res+=a[i]-x; } if(res>=m) return true; else return false; } int main() { ll minn=INT_MAX,maxn=INT_MIN; cin>>n>>m; for(int i=0;i<n;i++) { cin>>a[i]; minn=min(minn,a[i]); maxn=max(maxn,a[i]); } ll l=minn,r=maxn; while(r-l>1) { ll mid=(r+l)/2; if(check(mid)) l=mid; else r=mid; } if(check(r)) cout<<r; else cout<<l; return 0; }
1 comments
-
三石冲冲冲 LV 7 @ 2024-4-10 11:07:56
你的check函数里面的res要定义成ll,不能是Int,因为m<=2e9,你的res是砍树的高度和,可能会超出Int的范围
- 1
Information
- ID
- 89
- Time
- 1000ms
- Memory
- 256MiB
- Difficulty
- 7
- Tags
- # Submissions
- 913
- Accepted
- 203
- Uploaded By