-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1604.cpp
42 lines (38 loc) · 997 Bytes
/
1604.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
#include <iostream>
#include <algorithm>
using namespace std;
bool comp(pair<int, int> &a, pair<int, int> &b) {
return a.second > b.second;
}
void shift_signs_value(pair<int, int> *signs, int n, int i) {
int j = i + 1;
while (signs[i].second < signs[j].second) {
swap(signs[i], signs[j]);
i++, j++;
if (j == n) break;
}
}
int main() {
int n = 0;
cin >> n;
pair<int, int> signs[n]; //<index, number of signs left>
int sum = 0;
for (int i = 0; i < n; ++i) {
int x = 0;
cin >> x;
sum += x;
signs[i] = make_pair(i + 1, x);
}
sort(signs, signs + n, comp);
while (sum--) {
cout << signs[0].first << " ";
signs[0].second--;
if (n > 1 && signs[1].second > 0) {
cout << signs[1].first << " ";
signs[1].second--;
sum--;
}
if (n > 2) shift_signs_value(signs, n, 1);
if (n > 1) shift_signs_value(signs, n, 0);
}
}