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
#include<cstdio>
#include<vector>
#include<algorithm>
#include<queue>
using namespace std;
vector <int> v;
int t[5000013];
priority_queue <vector<int>, vector<vector<int> >, greater<vector<int> > > q;
int main()
{
    int n,m;
    int x,y;
    scanf ("%d %d", &n, &m);
    for (int i=0; i<n; i++)
    {
        scanf ("%d", &x);
        v.push_back(x);
    }
    v.push_back(1);
    q.push(v);
    for (int i=0; i<m-1; i++)
    {
        scanf ("%d %d", &x, &y);
        v[x-1]=y;
        v[n]=i+2;
        q.push(v);
    }
    while (!q.empty())
    {
        printf ("%d ", q.top()[n]);
        q.pop();
    }
    return 0;
}