fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. int n, i, med, pos;
  6. cin >> n;
  7. int arr1[n];
  8. int arr2[n];
  9. for(i=0; i<n; i++) { cin >> arr1[i]; arr2[i]=arr1[i]; }
  10. sort(arr2, arr2+n);
  11. med = arr2[n/2];
  12. for(i=0; i<n; i++) {
  13. if(med==arr1[i]){pos=i; break;}
  14. }
  15. cout << med << ' ' << pos;
  16. return 0;
  17. }
Success #stdin #stdout 0s 5296KB
stdin
5
3 1 2 4 5
stdout
3 0