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

Standard Template Library
Posted by Madhav 11 Jun 2008 17:19
Standard template library is not available or what?
i am getting compilation error for this problem.This is my code
<code>
#include<iostream>
#include<algorithm>
using namespace std;
class node{
        public:
                int id,prob;
                bool operator<(const node &n)const{
                        return (prob>n.prob);
                }
};
int main()
{
        int n;
        scanf("%d",&n);
        node arr[n];
        for(int i=0;i<n;i++){
                scanf("%d%d",&arr[i].id,&arr[i].prob);
        }
        sort(arr,arr+n);
        for(int i=0;i<n;i++)
        {
                printf("%d %d\n",arr[i].id,arr[i].prob);
        }
        return 0;
}
</code>

Edited by author 11.06.2008 17:19
Re: Standard Template Library
Posted by [MSU Detritus] freopen 30 Jul 2010 11:25
just replace sort funcion to stable_sort
Re: Standard Template Library
Posted by dAFTc0d3r [Yaroslavl SU] 27 Aug 2010 20:57
Madhav wrote 11 June 2008 17:19
Standard template library is not available or what?
i am getting compilation error for this problem.This is my code
<code>
#include<iostream>
#include<algorithm>
using namespace std;
class node{
        public:
                int id,prob;
                bool operator<(const node &n)const{
                        return (prob>n.prob);
                }
};
int main()
{
        int n;
        scanf("%d",&n);
        node arr[n];
        for(int i=0;i<n;i++){
                scanf("%d%d",&arr[i].id,&arr[i].prob);
        }
        sort(arr,arr+n);
        for(int i=0;i<n;i++)
        {
                printf("%d %d\n",arr[i].id,arr[i].prob);
        }
        return 0;
}
</code>

Edited by author 11.06.2008 17:19

1) node arr[n]; << ??
node arr[150000];

2) If you put node arr[150000]; in main - you'll get stack overflow.
Make so:
node arr[150000];
int main()
{
        int n;
        scanf("%d",&n);
...

3) Use stabe_sort instead of sort, or you catch WA#4.

After that you'll get AC.
http://acm.timus.ru/status.aspx?space=1&count=1&from=3148125

Good luck!