-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbox.cpp
More file actions
65 lines (57 loc) · 1.1 KB
/
box.cpp
File metadata and controls
65 lines (57 loc) · 1.1 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
#include<bits/stdc++.h>
using namespace std;
vector<int> box;
vector<int>::iterator it, m;
int main()
{
int n;
cin>>n;
int reorder = 0;
int curr = 1;
int a[n];
int k = 0;
int inorder;
int state = 0;
for(int i=0;i<2*n;i++)
{
string str;
cin>>str;
int e;
if(str == "add")
{
cin>>e;
k++;
box.push_back(e);
state = 0;
}
else if(str == "remove")
{
if(curr == box[k-1])
{
//cout<<boxes.top()<<" "<<curr<<endl;
box.pop_back();
curr = curr + 1;
k--;
}
else
{
int min = INT_MAX;
m = box.begin();
//sort(box.begin(),box.end(),greater<int>());
for(it = box.begin();it!=box.end();it++)
{
if(*it < min){ m = it; min = *it;}
}
box.erase(m);
box.push_back(min);
reorder = reorder + 1;
state = 1;
//cout<<boxes.top()<<endl;
box.pop_back();
k--;
curr = curr + 1;
}
}
}
cout<<reorder<<" ";
}