Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <iostream>
- #include <cstdlib>
- using namespace std;
- int main()
- {
- int n, temp, d, min, max, len, s, res;
- int a[5000], b[5000];
- res = 0;
- cin >> n;
- //cout << endl;
- for (int i = 0; i < n; ++i)
- {
- cin >> a[i];
- }
- for (int d = 1; d <= n; ++d)
- {
- for (int start = 0; start <= d - 1; ++start)
- {
- len = 0;
- s = 0;
- //min = max = 0;
- for (int i = start, j = 0; i < n; i += d, ++j)
- {
- ++len;
- b[j] = a[i];
- }
- min = max = b[0];
- for (int i = 0; i < len; ++i)
- {
- s += b[i];
- if (s > max)
- {
- max = s;
- }
- if (s < min)
- {
- min = s;
- }
- }
- if (max - min > res)
- {
- res = max - min;
- }
- }
- }
- cout << res;
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement