超时可以接受,现在WA真是看不懂了。程序逻辑错了嘛?我就想用循环解这个题。
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
long long n,m;
long long res = m;
vector<long long> v;
cin >> n >> m;
for(long long i = 0; i < n; i++){
long long a;
cin >> a;
v.push_back(a);
}
for(long long h = *max_element(v.begin(), v.end()) ; h > 0; h--){
res = m ;
for(auto tree : v){
if(tree > h ){
res = res - (tree - h);
}
}
if(res == 0){
cout << h << endl;
return 0;
}
}
}