1 solutions
-
0
C++ :
#include <bits/stdc++.h> #define N 1005 using namespace std; int a[N]; void solve(){ int n; cin >> n; memset(a,sizeof a,0); for (int i = 0;i<n;i++){ cin >> a[i]; } sort(a,a+n); int pos = n / 2; int ans = 0; for (int i = 0;i<n;i++) ans += abs(a[i]-a[pos]); cout << a[pos] << " " << ans << endl; } int main(){ int t; cin >> t; while(t--){ solve(); } return 0; }
- 1
Information
- ID
- 262
- Time
- 1000ms
- Memory
- 128MiB
- Difficulty
- (None)
- Tags
- # Submissions
- 0
- Accepted
- 0
- Uploaded By