ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1100. Final Standings

Why my code doesn't work with c++ 'sort' ? But it works fine with stable_sort o_O
Posted by sirius_lyra 9 Feb 2018 13:50
/*
* @Author: eleven
* @Date:   2017-05-21 02:50:38
* @Last Modified by:   eleven
* @Last Modified time: 2018-02-09 14:49:14
*/

// Status : AC ( works with stable_sort )
// doesn't works with sort

#include <bits/stdc++.h>

using namespace std;

#define SIZE 150005

struct team{
    int id;
    int solved;
}teams[SIZE];

bool foo(team lhs, team rhs){
return lhs.solved > rhs.solved;
}

void print(int n ){

    for(int i= 0; i<n ; ++i){
        cout<<teams[i].id<<" "<<teams[i].solved<<'\n';
    }
}


int main(){


    //freopen("in","r",stdin);
    //freopen("out","w",stdout);

    int n ;

    cin>>n;

    for(int i = 0; i<n ; ++i){
        cin>>teams[i].id>>teams[i].solved;
    }

    stable_sort(teams,teams+n ,foo);

    print(n);

    return 0;

}