Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
781 B
2
Indexable
Never
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int n;
int licznik;

vector < int > tab;
vector < int > tab1;
vector < int > pref;
int x;
int mx;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);

  cin >> n;
  tab.resize(n);
  tab1.resize(n - 1);
  pref.resize(n);

  for (int i = 0; i < n; i++) {
    cin >> x;
    tab[i] = x;
  }
  pref[0] = 0;
  for (int i = 0; i < n - 1; i++) {
    cin >> x;
    pref[i + 1] = pref[i] + x;
    tab1[i] = x;
  }

  x = 0;
  for (int i = 0; i < n; i++) {

    for (int j = i + 1; j < n; j++) {

      x = abs(tab[i] - tab[j]) - (pref[j] - pref[i]);
      if (x > mx) {
        mx = x;
      }
    }

  }

  cout << mx;

  return 0;
}