-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.cpp
64 lines (60 loc) · 1.28 KB
/
main.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
//
// main.cpp
// 1083 소트
//
// Created by 이준영 on 2020/12/03.
//
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <deque>
using namespace std;
int N,S;
deque<int> deq;
int main(int argc, const char * argv[]) {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> N;
for(int i = 1; i <= N; i++){
int num;
cin >> num;
deq.push_back(num);
}
cin >> S;
for(int i = 0; i < N; i++){
int tempS = 0, nowS = 0, j = i;
int nowmax = deq[i];
deque<int> temp;
while(nowS <= S and j < deq.size()){
if(deq[j] > nowmax){
nowmax = deq[j];
tempS = nowS;
}
nowS++;
j++;
}
S = S - tempS;
j = 0;
while(!deq.empty()){
if(j == i){
temp.push_back(nowmax);
j++;
continue;
}
if(deq.front() == nowmax){
deq.pop_front();
continue;
}
temp.push_back(deq.front());
deq.pop_front();
j++;
}
deq = temp;
}
for(int i = 0; i < deq.size(); i++){
cout << deq[i] << " ";
}
return 0;
}