-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAlyona_and_mex.cpp
More file actions
65 lines (61 loc) · 1.13 KB
/
Alyona_and_mex.cpp
File metadata and controls
65 lines (61 loc) · 1.13 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/*
AUTHOR: Antarikshya Mitra
TIME: 2:20 AM - 3:09 AM
PROBLEM NO:- Alyona and Mex
*/
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
const int MOD = 1e9 + 7;
void solve(vector<int> arr,int &siz)
{
int n = arr.size();
int min_siz = INT_MAX;
pair<int,int> indices;
for(int i=0;i<n;i+=2)
{
if(min_siz>abs(arr[i]-arr[i+1])+1)
{
indices.first = arr[i];
indices.second = arr[i+1];
min_siz = abs(arr[i]-arr[i+1])+1;
}
// min_siz = min(min_siz,abs(arr[i]-arr[i+1])+1);
}
cout<<min_siz<<endl;
// cout<<indices.first<<" "<<indices.second<<endl;
vector<int> ans(siz,-1);
int cnt = 0;
for(int i=indices.first-1;i<=indices.second-1;i++)
{
ans[i] = cnt;
cnt++;
}
cnt = 0;
for(int i = 0;i<siz;i++)
{
if(ans[i]!=-1){
cnt=0;
continue;
}
ans[i] = cnt;
cnt++;
}
for(int i=0;i<siz;i++)
cout<<ans[i]<<" ";
return;
}
int32_t main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int n,m;
cin>>n>>m;
vector<int> arr(m*2);
for (auto &a:arr)
cin>>a;
solve(arr,n);
return 0;
}