Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <iomanip>
- #include<algorithm>
- #include<cstdlib>
- #include<cstring>
- using namespace std;
- #define ll long long
- void Ahmed_Negm(){
- ios_base :: sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
- #ifndef ONLINE_JUDGE
- freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
- #endif
- }
- int main()
- {Ahmed_Negm();
- int n, t, res, min, flag = 1;
- cin>>t;
- while(t--){
- cin>>n;
- int arr[n];
- for(int i =0; i<n; i++){
- cin>>arr[i];
- }
- for(int j = 1; j<=n; j++){
- for(int z = j+1; z<=n; z++){
- res = (arr[j-1]+arr[z-1]+(z-j));
- if(flag==1){
- min = res;
- flag = 0;
- }
- if(flag == 0 && res<min){
- min = res;
- }
- }
- }
- flag = 1;
- cout<<res;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment