Skip to content

Commit c469f94

Browse files
committed
Add 05121.cpp
1 parent dd89f60 commit c469f94

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

05xxx/05121.cpp

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#include <algorithm>
2+
#include <iostream>
3+
#include <vector>
4+
using namespace std;
5+
6+
void solve(int idx) {
7+
int n, w; cin >> n >> w;
8+
vector<int> s(n+1);
9+
for (int i=1; i<=n; i++) cin >> s[i];
10+
for (int i=1; i<=n; i++) s[i] += s[i-1];
11+
12+
int mn = 1e9, mx = -1e9;
13+
for (int i=w; i<=n; i++) {
14+
mn = min(mn, (s[i]-s[i-w]) / w);
15+
mx = max(mx, (s[i]-s[i-w]) / w);
16+
}
17+
cout << "Data Set " << idx << ":\n" << mx-mn << "\n\n";
18+
}
19+
20+
int main(void) {
21+
ios::sync_with_stdio(false);
22+
cin.tie(nullptr);
23+
24+
int k; cin >> k;
25+
for (int i=1; i<=k; i++) solve(i);
26+
return 0;
27+
}

0 commit comments

Comments
 (0)