Ahmed_Negm

Untitled

Dec 18th, 2021
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.74 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <iomanip>
  4. #include<algorithm>
  5. #include<cstdlib>
  6. #include<cstring>
  7. using namespace std;
  8. #define ll long long
  9.  
  10. void Ahmed_Negm(){
  11.   ios_base :: sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  12.   #ifndef ONLINE_JUDGE  
  13.     freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
  14.   #endif
  15. }
  16.  
  17. int main()
  18. {Ahmed_Negm();
  19.  
  20. int n, t, res, min, flag = 1;
  21. cin>>t;
  22. while(t--){
  23. cin>>n;
  24. int arr[n];
  25. for(int i =0; i<n; i++){
  26. cin>>arr[i];
  27. }
  28. for(int j = 1; j<=n; j++){
  29. for(int z = j+1; z<=n; z++){
  30. res = (arr[j-1]+arr[z-1]+(z-j));
  31. if(flag==1){
  32.   min = res;
  33.   flag = 0;
  34. }
  35. if(flag == 0 && res<min){
  36.   min = res;
  37. }
  38. }
  39.  
  40. }
  41. flag = 1;
  42. cout<<res;
  43.  
  44. }
  45.  
  46. return 0;
  47.  }
Advertisement
Add Comment
Please, Sign In to add comment