Skip to content

Commit

Permalink
Merge pull request #1 from isha0904/StickLength
Browse files Browse the repository at this point in the history
Solution to Stick Lengths Problem - Google-Developer-Student-Club-CCOEW#144
  • Loading branch information
isha0904 authored Oct 19, 2023
2 parents 271de08 + 4021633 commit 0cf4909
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions SolutionToStickLengthsProblem.txt
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;
}

0 comments on commit 0cf4909

Please sign in to comment.