forked from AadeshSalecha/Zonal-Computing-Olympiad
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSuitcase Swappers.cpp
43 lines (37 loc) · 1.08 KB
/
Suitcase Swappers.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
#include <utility>
#include <numeric>
using namespace std;
const int MAX = 20000;
int arr[MAX];
bool cmp(pair<int, int> a, pair<int, int> b)
{
return a.first < b.first;
}
int main(void)
{
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
int n, m, temp, dist, belt; scanf("%d%d", &n, &m);
vector < pair<int, int> > monkeys;
for(int i = 0; i < m; i++)
{
scanf("%d%d", &dist, &belt);
monkeys.push_back(make_pair(dist, belt));
}
sort(monkeys.begin(), monkeys.end(), cmp);
for(int i = 1; i <= n; i++)
arr[i-1] = i;
for(int i = 0; i < m; i++)
{
temp = arr[monkeys[i].second-1];
arr[monkeys[i].second-1] = arr[monkeys[i].second];
arr[monkeys[i].second] = temp;
}
for(int i = 0; i < n; i++)
printf("%d ", arr[i]);
printf("\n");
}