Advertisement
Guest User

Untitled

a guest
Apr 30th, 2017
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.78 KB | None | 0 0
  1. #include "stdafx.h"
  2.  
  3. #include <iostream>
  4. #include <cstdlib>
  5.  
  6.  
  7. using namespace std;
  8.  
  9. int main()
  10. {
  11.     int n, temp, d, min, max, len, s, res;
  12.     int  a[5000], b[5000];
  13.     res = 0;
  14.     cin >> n;
  15.     //cout << endl;
  16.     for (int i = 0; i < n; ++i)
  17.     {
  18.         cin >> a[i];
  19.     }
  20.  
  21.     for (int d = 1; d <= n; ++d)
  22.     {
  23.         for (int start = 0; start <= d - 1; ++start)
  24.         {
  25.             len = 0;
  26.             s = 0;
  27.             //min = max = 0;
  28.             for (int i = start, j = 0; i < n; i += d, ++j)
  29.             {
  30.                 ++len;
  31.                 b[j] = a[i];
  32.             }
  33.             min = max = b[0];
  34.             for (int i = 0; i < len; ++i)
  35.             {
  36.                 s += b[i];
  37.                 if (s > max)
  38.                 {
  39.                     max = s;
  40.                 }
  41.                 if (s < min)
  42.                 {
  43.                     min = s;
  44.                 }
  45.             }
  46.             if (max - min > res)
  47.             {
  48.                 res = max - min;
  49.             }
  50.  
  51.  
  52.         }
  53.     }
  54.     cout << res;
  55.     system("pause");
  56.     return 0;
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement