From a4656de92f1f340416c314732df9572d2d5493dc Mon Sep 17 00:00:00 2001 From: Nik404 <44531098+Nik404@users.noreply.github.com> Date: Tue, 21 Dec 2021 16:23:03 +0530 Subject: [PATCH] nlogn sorting algo --- .../icpcStandings_nlogn.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 Section 05 - sorting and searching/icpcStandings_nlogn.cpp diff --git a/Section 05 - sorting and searching/icpcStandings_nlogn.cpp b/Section 05 - sorting and searching/icpcStandings_nlogn.cpp new file mode 100644 index 0000000..5c594e1 --- /dev/null +++ b/Section 05 - sorting and searching/icpcStandings_nlogn.cpp @@ -0,0 +1,17 @@ +#include +using namespace std; + +bool compare(paira, pair b){ + return a.second < b.second; +} + +int badness(vector > teams){ + //Complete this function to return the min badness + sort(teams.begin(), teams.end(), compare); + int cnt = 0; + for(int i = 0; i < teams.size(); i++){ + int j = i+1; + cnt += abs(teams[i].second-j); + } + return cnt; +} \ No newline at end of file