Untitled
unknown
plain_text
2 years ago
1.1 kB
10
Indexable
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll minDiffPairValue(vector<ll> &arr,int n)
{
int i;
ll mn=LLONG_MAX;
for(i = 0; i < n-1; i++)
{
mn=min(mn,abs(arr[i]-arr[i+1]));
}
return mn;
}
void solution(vector<ll> &array, int operation) {
int i;
ll diff;
for (i = 0; i < operation; i++) {
diff = minDiffPairValue(array, array.size());
array.push_back(diff);
}
cout << diff << endl;
}
int main()
{
int numberOfTests;
int n; // lenght of array
int operations; // number of operation
int i, j;
ll key;
vector<ll> array;
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> numberOfTests;
for (i = 0; i < numberOfTests; i++) {
cin >> n;
cin >> operations;
array.clear();
for(j = 0; j < n; j++) {
cin >> key;
array.push_back(key);
}
solution(array, operations);
}
return 0;
}Editor is loading...
Leave a Comment