CodeForce上貌似有类似的题目 总和取商,有余数就加一,还要保证最大值不能超过答案
#include<iostream>
#include<cstdio>
#include<set>
#include<string>
#include<string.h>
#include<cstring>
#include<vector>
#include<map>
#include<queue>
#include<stack>
#include<cctype>
#include<algorithm>
#include<sstream>
#include<utility>
#include<cmath>
#define mt(a) memset(a,0,sizeof (a))
#define fl(a,b,c) fill(a,b,c)
#define SWAP(a,b,t) (t=a,a=b,b=t)
#define inf 1000000
using namespace std;
typedef long long ll;
int main()
{
int T;
cin >> T;
while (T--)
{
int n,m;
scanf("%d %d", &n, &m);
ll sum = 0, temp;
int maxx = 0;
for (int i = 0; i < n; i++)
{
scanf("%lld", &temp);
maxx = maxx>temp?maxx:temp;
sum += temp;
}
ll ans = sum / m;
if (sum%m)ans++;
if (ans < maxx)ans = maxx;
printf("%lld\n", ans);
}
return 0;
}