Asked 5 months ago
0 Answers
1 Views
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
int maxDistance(vector<int>& arr) {
int n = arr.size();
int maxDist = 0;
for (int i = 0; i < n; i++) {
int sum = 0;
for (int j = 0; j < n; j++) {
sum += arr[(i + j) % n];
maxDist = max(maxDist, abs(sum));
}
}
return maxDist;
}
int main() {
int n;
cin >> n;
vector<int> arr(n);
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
cout << maxDistance(arr) << endl;
return 0;
}
Share