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

С++ TLE(test 12)
Posted by Bohdan 28 Mar 2017 02:15
#include <iostream>
using namespace std;

int main()
{
    long N;
    cin >> N;
    long **array = new long*[N];
    for (long i = 0; i < N; i++)
    {
        array[i] = new long[2];
        long temp, temp2;
        cin >> temp >> temp2;
        array[i][0] = temp;
        array[i][1] = temp2;
    }
    cout << endl << endl;

    long l, r, i, k, buf;
    k = l = 0;
    r = N - 2;
    while (l <= r)
    {
        for (i = l; i <= r; i++)
            if (array[i][1] < array[i + 1][1])
            {
                swap(array[i], array[i + 1]);
                k = i;
            }
        r = k - 1;
        for (i = r; i >= l; i--)
            if (array[i][1] < array[i + 1][1])
            {
                swap(array[i], array[i + 1]);
                k = i;
            }
        l = k + 1;
    }
        for (long i = 0; i < N; i++)
        {
            cout << array[i][0] << " " << array[i][1] << endl;
        }
        return 0;
    }

What is wrong with it?( I use bubbleshaker sort.
Re: С++ TLE(test 12)
Posted by ToadMonster 28 Mar 2017 04:07
You shouldn't use bubble sort. You the only should receive the same sort result.