-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpriority_queue.cpp
More file actions
63 lines (63 loc) · 773 Bytes
/
priority_queue.cpp
File metadata and controls
63 lines (63 loc) · 773 Bytes
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
#include <bits/stdc++.h>
using namespace std;
int main()
{
int i,temp,n,m,team,sums=0,j;
std::vector<int> v;
cin>>n;
cin>>m;
cin>>team;
for(i=0;i<n;i++)
{
cin>>temp;
v.push_back(temp);
}
priority_queue<int> a,b;
for(i=0;i<m;i++)
{
a.push(v[i]);
}
i--;
for(j=v.size()-1;j>=0;j--)
{
if(j<=i)
break;
b.push(v[j]);
}
j++;
int k,temp1,temp2;
for(k=0;k<team;k++)
{
temp1=0;
temp2=0;
if(!a.empty())
{
temp1=a.top();
}
if(!b.empty())
{
temp2=b.top();
}
if(temp1>=temp2 && !a.empty())
{
a.pop();
if(i+1<j)
{
a.push(v[i+1]);
i++;
}
}
else if(temp1<temp2 && !b.empty())
{
b.pop();
if(i<j-1)
{
b.push(v[j-1]);
j--;
}
}
sums=sums+max(temp1,temp2);
}
cout<<sums;
return 0;
}