Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions Section 05 - sorting and searching/icpcStandings_nlogn.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include<bits/stdc++.h>
using namespace std;

bool compare(pair<string,int>a, pair<string,int> b){
return a.second < b.second;
}

int badness(vector<pair<string,int> > 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;
}