-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1899B.cpp
More file actions
45 lines (43 loc) · 1022 Bytes
/
1899B.cpp
File metadata and controls
45 lines (43 loc) · 1022 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int t;
cin >> t;
while (t--)
{
int n;
cin >> n;
vector<ll> arr(n);
for (int i = 0; i < n; i++)
{
cin >> arr[i];
}
ll absdif = 0;
for (int i = 1; i <= n / 2; i++)
{
if (n % i == 0)
{
ll minimum = LONG_LONG_MAX;
ll maximum = 0;
ll temp = 0;
for (int j = 0; j < n; j++)
{
temp += arr[j];
if ((j + 1) % i == 0)
{
minimum = min(minimum, temp);
maximum = max(maximum, temp);
temp = 0;
}
}
absdif = max(absdif, maximum - minimum);
}
}
cout << absdif << '\n';
}
return 0;
}