Download uva_cpp_clean/10041/10041-2.cpp from slayone/uva_spoj_raw: direct link, hf CLI and curl.
- Browser
- Download file 1.78 kB
-
https://huggingface.co/datasets/slayone/uva_spoj_raw/resolve/main/uva_cpp_clean/10041/10041-2.cpp
- Command line
-
hf download hf://datasets/slayone/uva_spoj_raw/uva_cpp_clean/10041/10041-2.cpp
-
curl -L -o 10041-2.cpp https://huggingface.co/datasets/slayone/uva_spoj_raw/resolve/main/uva_cpp_clean/10041/10041-2.cpp
1.78 kB
| using namespace std; | |
| typedef long long ll; | |
| typedef pair<int, int> pii; | |
| typedef pair<ll, ll> pll; | |
| typedef long double ld; | |
| typedef vector<int> vi; | |
| typedef vector<ll> vll; | |
| typedef vector<pii> vpii; | |
| typedef vector<pll> vpll; | |
| const double EPS = 1e-9; | |
| const int N = 1e3+2, M = 3e5+5, OO = 0x3f3f3f3f; | |
| // int dx[] = {1,-1,0,0} , dy[] = {0,0,1,-1}; // 4 Direction | |
| // int dx[] = {1,-1,0,0,1,1,-1,-1}, dy[] = {0,0,1,-1,1,-1,1,-1}; // 8 Direction | |
| // int dx[] = {1,-1,1,-1,2,2,-2,-2} , dy[] = {2,2,-2,-2,1,-1,1,-1}; // Knight Direction | |
| // int dx[] = {2,-2,1,1,-1,-1} , dy[] = {0,0,1,-1,1,-1}; // Hexagonal Direction | |
| int main() { | |
| // ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); | |
| // freopen("input.txt", "r", stdin); | |
| // freopen("output.txt", "w", stdout); | |
| int tc; scanf("%d", &tc); | |
| while (tc--) { | |
| int n; scanf("%d", &n); | |
| vector<int> v(n); | |
| for(int& i: v) scanf("%d",&i); | |
| sort(all(v)); | |
| int b = 0, sum = 0; | |
| if(n%2!=0) b=v[n/2]; | |
| else b=v[n/2]; | |
| for(int i=n/2+1;i<n;i++) | |
| sum=sum+abs(v[i]-b); | |
| for(int i=n/2-1;i>=0;i--) | |
| sum=sum+abs(b-v[i]); | |
| printf("%d\n", sum); | |
| } | |
| return 0; | |
| } |