MohamedAbdel3al

Smallest Pair

Aug 8th, 2021
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <bits/stdc++.h>
  4. using namespace std ;
  5. typedef long long ll ;
  6.  
  7.  
  8. int main() {
  9.  
  10. ios_base::sync_with_stdio(false) , cin.tie(nullptr) , cout.tie(nullptr) ;
  11. int n , t ;
  12. ll count = 0 , MIN = INT_MAX ;
  13. cin >> t ;
  14. while (t--) {
  15. cin >> n ; int arr[n] ;
  16. for (int i = 1; i <= n ; i++) cin >> arr[i] ;
  17. for (int i = 1; i <= n; i++) {
  18. for (int j = i + 1; j <= n; j++) {
  19. count = arr[i] + arr[j] + j - i ;
  20. MIN = min(count , MIN) ;
  21. }
  22. }
  23. }
  24. cout << MIN ;
  25.  
  26. return 0 ;
  27. }
  28.  
  29.  
Advertisement
Add Comment
Please, Sign In to add comment