Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int diferencia(vector <int> &numeros, int pos)
- {
- vector <int> v;
- for(int i=0; i<numeros.size(); i++)
- {
- if(i != pos)
- {
- v.push_back(numeros[i]);
- }
- }
- int sumaDif = 0;
- for(int i=1; i<v.size(); i++)
- {
- sumaDif += abs(v[i]-v[i-1]);
- }
- return sumaDif;
- }
- int main()
- {
- int n;
- cin >> n;
- vector <int> v(n);
- for(int i=0; i<n; i++)
- cin >> v[i];
- int minSumaDif = diferencia(v, 1);
- int res = 2;
- for(int i=1; i<n-1; i++)
- {
- int d = diferencia(v, i);
- if(d <= minSumaDif)
- {
- minSumaDif = d;
- res = i+1;
- }
- }
- cout << res << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement