-
Notifications
You must be signed in to change notification settings - Fork 3
/
D.cpp
88 lines (72 loc) · 1.42 KB
/
D.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include<bits/stdc++.h>
using namespace std;
typedef pair<int, int> pi;
int main()
{
int n, m,i,j=0,k,l,p,x;
cin>>n>>m;
vector<pi> a(m+1);
for (i=0; i<m; i++)
{
cin>>x;
a[i]= {x,i};
}
sort(a.rbegin(), a.rend());
vector<int>ans(n);
for (i=0; i<n; i+=2)
{
if (a[j].first == 0) j++;
if (j == m)
{
ans.resize(0);
break;
}
ans[i] = a[j].second+1;
a[j].first--;
}
if (n > 1 && n%2 == 1 && j == 0)
{
j++;
if (j >= m)
{
ans.resize(0);
}
a[j].first--;
ans[n-1] = a[j].second + 1;
}
if (ans.size() > 0)
{
if (j == 0) j++;
for (i=1; i<n; i+=2)
{
if (a[j].first == 0) j++;
if (j >= m)
{
ans.resize(0);
break;
}
ans[i] = a[j].second+1;
a[j].first--;
}
}
if (n > 1 && ans.size() > 0 && ans[n-2] == ans[n-1])
{
j++;
if (j >= m)
{
ans.resize(0);
}
else
{
ans[n-1] = a[j].second + 1;
}
}
if (ans.size() == 0)
{
cout<<-1<<"\n";
}
for (i=0; i<ans.size(); i++)
{
cout<<ans[i]<<" ";
}
}