1656A - Good Pairs - CodeForces Solution


constructive algorithms math

Please click on ads to support us..

Python Code:

for t in range(int(input())):
    n = int(input())
    ar = list(map(int,input().split()))
    a = max(ar)
    b = min(ar)
    c = ar.index(a)+1
    d = ar.index(b)+1
    print(f"{c} {d}")

C++ Code:

#include<bits/stdc++.h>
#define ll long long
#define yes cout<<"YES\n";
#define no  cout<<"NO\n";
#define first F
#define second S
using namespace std;

int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL); // flushes cout
int t;
cin>>t;
int x,y,k;
while(t--){
    cin>>x;
    int a=0;
    vector<int>arr(x);
    for(int i=0;i<x;i++)
        cin>>arr[i];
    int k1=min_element(arr.begin(),arr.end())-arr.begin();
    int k2=max_element(arr.begin(),arr.end())-arr.begin();
    cout<<min(k1,k2)+1<<" "<<max(k1,k2)+1<<"\n";


}
}


Comments

Submit
0 Comments
More Questions

1711B - Party
1702D - Not a Cheap String
1714F - Build a Tree and That Is It
1703F - Yet Another Problem About Pairs Satisfying an Inequality
610A - Pasha and Stick
1200A - Hotelier
1091A - New Year and the Christmas Ornament
1352B - Same Parity Summands
1102A - Integer Sequence Dividing
630B - Moore's Law
1004A - Sonya and Hotels
1680B - Robots
1690A - Print a Pedestal (Codeforces logo)
1295A - Display The Number
1077A - Frog Jumping
1714G - Path Prefixes
1369C - RationalLee
289B - Polo the Penguin and Matrix
1716A - 2-3 Moves
1670B - Dorms War
1716B - Permutation Chain
987A - Infinity Gauntlet
1676G - White-Black Balanced Subtrees
1716D - Chip Move
1352F - Binary String Reconstruction
1487B - Cat Cycle
1679C - Rooks Defenders
56A - Bar
1694B - Paranoid String
35A - Shell Game