Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <algorithm>
- using namespace std;
- struct team
- {
- int number;
- int point;
- int time;
- };
- void merge_series (team *arr, int first, int last_1, int last_2, int *dubl, int *ind)
- {
- int i = first;
- int j = last_1+1;
- int c = 0;
- for (c = first; c <= last_2; c++)
- if (j > last_2)
- dubl[c] = ind[i++];
- else if (i > last_1)
- dubl[c] = ind[j++];
- else if (arr[ind[i]].point > arr[ind[j]].point)
- dubl[c] = ind[i++];
- else if (arr[ind[i]].point == arr[ind[j]].point)
- {
- if (arr[ind[i]].time <= arr[ind[j]].time)
- dubl[c] = ind[i++];
- else dubl[c] = ind[j++];
- }
- else dubl[c] = ind[j++];
- }
- void sort (team *arr, int first, int last, int *dubl, int *ind)
- {
- int middle = (first + last)/2;
- if (first < middle)
- sort (arr, first, middle, dubl, ind);
- if (middle + 1 < last)
- sort (arr, middle+1, last, dubl, ind);
- merge_series (arr, first, middle, last, dubl, ind);
- for (int i = first; i <= last; i++)
- ind[i] = dubl[i];
- }
- int main ()
- {
- int n;
- int *ind, *dubl;
- cin >> n;
- team *arr = new team[n];
- ind = new int [n];
- dubl = new int [n];
- for (int i=0; i<n; i++)
- {
- arr[i].number = i+1;
- ind[i] = i;
- cin >> arr[i].point;
- cin >> arr[i].time;
- }
- sort (arr, 0, n-1, dubl, ind);
- for (int i=0; i<n; i++)
- cout << ind[i] + 1 << " ";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement