forked from Google-Developer-Student-Club-CCOEW/Competitive-Programming-2023-GDSC-CUMMINS-X-GDSC-MMCOE
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from isha0904/StickLength
Solution to Stick Lengths Problem - Google-Developer-Student-Club-CCOEW#144
- Loading branch information
Showing
1 changed file
with
23 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#include <bits/stdc++.h> | ||
using namespace std; | ||
|
||
int main() | ||
{ | ||
long long a, c = 0; | ||
cin >> a; | ||
int b[a]; | ||
|
||
for (int i; i < a; i++){ | ||
cin >> b[i]; | ||
} | ||
|
||
sort(b, b + a); | ||
|
||
for(int i; i < a; i++){ | ||
c += abs(b[a/2] - b[i]); | ||
} | ||
|
||
cout << c; | ||
|
||
return 0; | ||
} |