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

sort AC
Posted by xyqxyq 7 May 2019 08:05
Question requirements are ordered without changing order

#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;

const int maxn = 150005;
struct Node
{
    int index;
    int ID;
    int mount;
}node[maxn];

int N;

bool cmp(Node &a, Node &b)
{
    if (a.mount != b.mount)
    {
        return a.mount > b.mount;
    }
    else
    {
        return a.index < b.index;
    }
}

int main()
{
    scanf("%d", &N);
    for (int i=0; i<N; i++)
    {
        scanf("%d%d", &node[i].ID, &node[i].mount);
        node[i].index = i;
    }

    sort(node, node + N, cmp);

    for (int i=0; i<N; i++)
    {
        printf("%d %d\n", node[i].ID, node[i].mount);
    }
    return 0;
}