牛客多校(2020第十场)E Game
题目链接:https://ac.nowcoder.com/acm/contest/5675/E
题解:求最大前缀平均值
1 #include<unordered_map>
2 #include<vector>
3 #include<iostream>
4 #include<cstring>
5 #include<algorithm>
6 #include<queue>
7 #include<cmath>
8 #include<cstring>
9
10 using namespace std;
11 #define ll long long
12 const ll N = 105 + 5;
13
14 inline ll read() {
15 ll x = 0, f = 1;
16 char ch = getchar();
17 while(ch<'0'||ch>'9'){
18 if(ch=='-')
19 f=-1;
20 ch=getchar();
21 }
22 while(ch>='0'&&ch<='9'){
23 x = x * 10 + ch - '0';
24 ch = getchar();
25 }
26 return x * f;
27 }
28
29 ll a[N];
30
31 void solve(int n) {
32 int sum = 0, max_high = 0;
33 for (int i = 1; i <= n; i++) {
34 sum += a[i];
35 max_high = max(max_high, (sum+i-1) / i);
36 }
37 cout << max_high << "\n";
38 }
39
40 int main() {
41 int t =read();
42 while (t--) {
43 int n =read();
44 for (int i = 1; i <= n; i++) {
45 a[i] = read();
46 }
47
48 solve(n);
49 }
50 return 0;
51 }
52
53 /*
54 100
55 8
56 2 5 1 4 4 6 3 2
57 6
58 1 2 7 8 1 1
59 8
60 6 6 1 2 7 8 1 1
61 8
62 4 4 1 2 7 8 1 1
63 8
64 3 3 1 2 7 8 1 1
65 */

浙公网安备 33010602011771号